Skip to content

Commit

Permalink
Msvc fixes (#3348)
Browse files Browse the repository at this point in the history
* Fix wrong dllexport MACRO.

* Use portable `std::chrono` instead of `gettimeofday` not available for msvc.

* Split (too) long string as msvc has length limit :-/

* Fix `#include` for msvc

* Workaround for msvc: explicit conversion to function pointer (with expected call type convention).

* Fix `WINAPI` placement.

* Msvc already has `CreatePseudoConsole`/`ClosePseudoConsole`.

* Msvc doesn't have `MSWEnableDarkMode`.

* Workaround for msvc: `<windows.h>` `#define`s `small` (as `char`) :-/
  • Loading branch information
Jarod42 committed Apr 15, 2024
1 parent 3f5be91 commit eae047a
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CodeLite/LSP/Notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace LSP
{

class WXDLLIMPEXP_SDK Notification : public LSP::MessageWithParams
class WXDLLIMPEXP_CL Notification : public LSP::MessageWithParams
{
public:
Notification();
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace LSP
{

class WXDLLIMPEXP_SDK Request : public LSP::MessageWithParams
class WXDLLIMPEXP_CL Request : public LSP::MessageWithParams
{
int m_id = wxNOT_FOUND;
wxString m_server_name;
Expand Down
1 change: 0 additions & 1 deletion CodeLite/SocketAPI/clSocketBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#define CLSOCKETBASE_H

#include <string>
#include <sys/param.h>
#include <wx/msgqueue.h>
#include <wx/sharedptr.h>
#include <wx/string.h>
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/clConsoleMateTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "clConsoleGnomeTerminal.h"

class WXDLLIMPEXP_SDK clConsoleMateTerminal : public clConsoleGnomeTerminal
class WXDLLIMPEXP_CL clConsoleMateTerminal : public clConsoleGnomeTerminal
{
public:
clConsoleMateTerminal();
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/clConsoleXfce4Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CLCONSOLEXFCE4TERMINAL_H

#include "clConsoleGnomeTerminal.h"
class WXDLLIMPEXP_SDK clConsoleXfce4Terminal : public clConsoleGnomeTerminal
class WXDLLIMPEXP_CL clConsoleXfce4Terminal : public clConsoleGnomeTerminal
{
public:
clConsoleXfce4Terminal();
Expand Down
10 changes: 4 additions & 6 deletions CodeLite/clModuleLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "fileutils.h"

#include <sys/time.h>
#include <chrono>
#include <wx/crt.h>
#include <wx/datetime.h>

Expand Down Expand Up @@ -43,12 +43,10 @@ wxString clModuleLogger::Prefix()
return wxEmptyString;
}

const auto now = std::chrono::system_clock::now().time_since_epoch();
const int ms = std::chrono::duration_cast<std::chrono::milliseconds>(now).count() % 1000;
const wxString msStr = wxString::Format(wxT("%03d"), ms);
wxString prefix;
timeval tim;
gettimeofday(&tim, NULL);
int ms = (int)tim.tv_usec / 1000.0;

wxString msStr = wxString::Format(wxT("%03d"), ms);
prefix << wxT("[") << wxDateTime::Now().FormatISOTime() << wxT(":") << msStr;
// add the thread ID
prefix << wxT(" T:") << wxThread::GetCurrentId();
Expand Down
10 changes: 4 additions & 6 deletions CodeLite/file_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "cl_standard_paths.h"

#include <sys/time.h>
#include <chrono>
#include <wx/crt.h>
#include <wx/filename.h>
#include <wx/log.h>
Expand Down Expand Up @@ -163,12 +163,10 @@ wxString FileLogger::Prefix(int verbosity)
return wxEmptyString;
}

const auto now = std::chrono::system_clock::now().time_since_epoch();
const int ms = std::chrono::duration_cast<std::chrono::milliseconds>(now).count() % 1000;
const wxString msStr = wxString::Format(wxT("%03d"), ms);
wxString prefix;
timeval tim;
gettimeofday(&tim, NULL);
int ms = (int)tim.tv_usec / 1000.0;

wxString msStr = wxString::Format(wxT("%03d"), ms);
prefix << wxT("[") << wxDateTime::Now().FormatISOTime() << wxT(":") << msStr;
switch(verbosity) {
case System:
Expand Down
8 changes: 6 additions & 2 deletions CodeLite/winprocess_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@

typedef VOID* HPCON;

typedef HRESULT WINAPI (*CreatePseudoConsole_T)(COORD size, HANDLE hInput, HANDLE hOutput, DWORD dwFlags, HPCON* phPC);
typedef VOID WINAPI (*ClosePseudoConsole_T)(HPCON hPC);
#if !defined(_MSC_VER)
typedef HRESULT(WINAPI* CreatePseudoConsole_T)(COORD size, HANDLE hInput, HANDLE hOutput, DWORD dwFlags, HPCON* phPC);
typedef VOID(WINAPI* ClosePseudoConsole_T)(HPCON hPC);

thread_local bool loadOnce = true;
thread_local CreatePseudoConsole_T CreatePseudoConsole = nullptr;
thread_local ClosePseudoConsole_T ClosePseudoConsole = nullptr;
#endif

#ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
#define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016
Expand Down Expand Up @@ -308,6 +310,7 @@ IProcess* WinProcessImpl::ExecuteConPTY(wxEvtHandler* parent, const wxString& cm
return nullptr;
}

#if !defined(_MSC_VER)
// Create the Pseudo Console, using the pipes
if(loadOnce) {
loadOnce = false;
Expand All @@ -318,6 +321,7 @@ IProcess* WinProcessImpl::ExecuteConPTY(wxEvtHandler* parent, const wxString& cm
FreeLibrary(hDLL);
}
}
#endif

if(!CreatePseudoConsole || !ClosePseudoConsole) {
::CloseHandle(inputReadSide);
Expand Down
2 changes: 1 addition & 1 deletion Debugger/debuggergdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

// On Windows lower than XP, the function DebugBreakProcess does not exist
// so we need to bind it dynamically
typedef BOOL WINAPI (*DBG_BREAK_PROC_FUNC_PTR)(HANDLE);
typedef BOOL(WINAPI* DBG_BREAK_PROC_FUNC_PTR)(HANDLE);
DBG_BREAK_PROC_FUNC_PTR DebugBreakProcessFunc = NULL;
HINSTANCE Kernel32Dll = NULL;

Expand Down
1 change: 1 addition & 0 deletions FileGrep/FileGrep/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <algorithm>
#include <iostream>
#include <locale>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
4 changes: 2 additions & 2 deletions LiteEditor/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool CodeLiteApp::OnInit()

#ifdef __WXMSW__
// HiDPI support
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
typedef BOOL(WINAPI * SetProcessDPIAwareFunc)();
HINSTANCE user32Dll = LoadLibrary(L"User32.dll");
if (user32Dll) {
SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(user32Dll, "SetProcessDPIAware");
Expand Down Expand Up @@ -361,7 +361,7 @@ bool CodeLiteApp::OnInit()

::wxInitAllImageHandlers();

#if defined(__WXMSW__)
#if defined(__WXMSW__) && !defined(_MSC_VER)
if (clConfig::Get().Read("CodeLiteAppearance", 0) == 1) {
// force dark
MSWEnableDarkMode(wxApp::DarkMode_Always);
Expand Down
2 changes: 1 addition & 1 deletion LiteEditor/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6184,7 +6184,7 @@ void clMainFrame::OnSetActivePoject(wxCommandEvent& e)
CHECK_COND_RET(!projects.empty());

// sort the entries
projects.Sort([](const wxString& first, const wxString& second) { return first.CmpNoCase(second) < 0; });
projects.Sort(+[](const wxString& first, const wxString& second) { return first.CmpNoCase(second) < 0; });

int initialSelection = projects.Index(cur_active_project);
clSingleChoiceDialog dlg(this, projects, initialSelection == wxNOT_FOUND ? 0 : initialSelection);
Expand Down
6 changes: 3 additions & 3 deletions Plugin/ColoursAndFontsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,16 +1114,16 @@ void ColoursAndFontsManager::SetThemeTextSelectionColours(const wxString& theme_
}
}

wxFont ColoursAndFontsManager::GetFixedFont(bool small) const
wxFont ColoursAndFontsManager::GetFixedFont(bool smaller) const
{
auto lexer = GetLexer("text");
auto font = lexer->GetFontForStyle(0, EventNotifier::Get()->TopFrame());
#ifndef __WXMAC__
if (small) {
if (smaller) {
font.SetFractionalPointSize(font.GetPointSize() * 0.9);
}
#else
wxUnusedVar(small);
wxUnusedVar(smaller);
#endif
return font;
}
Expand Down
2 changes: 1 addition & 1 deletion Plugin/ColoursAndFontsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class WXDLLIMPEXP_SDK ColoursAndFontsManager : public wxEvtHandler
/**
* @brief return the default editor font (monospaced)
*/
wxFont GetFixedFont(bool small = false) const;
wxFont GetFixedFont(bool smaller = false) const;
/**
* @brief return a suitable background colour that matches the lexer's bg colour
*/
Expand Down
2 changes: 1 addition & 1 deletion codelite-generate-themes/codelite-generate-themes/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MainApp : public wxApp
{

#ifdef __WXMSW__
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
typedef BOOL(WINAPI * SetProcessDPIAwareFunc)();
HINSTANCE user32Dll = LoadLibrary(L"User32.dll");
if(user32Dll) {
SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(user32Dll, "SetProcessDPIAware");
Expand Down
2 changes: 1 addition & 1 deletion ctagsd/tests/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ class MainApp : public wxApp
// m_persistencManager = new clPersistenceManager();
// wxPersistenceManager::Set(*m_persistencManager);
#ifdef __WXMSW__
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
typedef BOOL (WINAPI* SetProcessDPIAwareFunc)();
HINSTANCE user32Dll = LoadLibrary(L"User32.dll");
if(user32Dll) {
SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(user32Dll, "SetProcessDPIAware");
Expand Down
2 changes: 1 addition & 1 deletion wxcrafter/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static const wxCmdLineEntryDesc cmdLineDesc[] = {
IMPLEMENT_APP(wxcApp)

#ifdef __WXMSW__
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
typedef BOOL(WINAPI* SetProcessDPIAwareFunc)();
#endif

wxcApp::wxcApp()
Expand Down
2 changes: 1 addition & 1 deletion wxcrafter/src/wxcLicenseGPL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ the "copyright" line and a pointer to where the full notice is found.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
)" R"(
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Expand Down

0 comments on commit eae047a

Please sign in to comment.