Skip to content

Commit

Permalink
MAIN: Add a small WinMain/wWinMain on Windows
Browse files Browse the repository at this point in the history
Just using main(), especially when building with -municode, doesn't
seem to work with Qt.

Normally, the Qt way would be to link against qtmain, but that doesn't
work with -municode either.

Instead, we're doing it ourselves, then.
  • Loading branch information
DrMcCoy committed Jun 25, 2018
1 parent 7ceaf08 commit 7854a93
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ elseif(CMAKE_HOST_WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt.lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else()
add_compile_options(-municode)
add_compile_options(-mwindows -municode)
endif()
else()
message(STATUS "Unknown platform, maybe not supported")
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ case "$target" in
AM_CONDITIONAL(WIN32, false)
;;
*mingw*)
PHAETHON_CFLAGS="-mconsole -municode"
PHAETHON_CFLAGS="-mwindows -municode"
PHAETHON_LIBS=""
AM_CONDITIONAL(WIN32, true)
;;
Expand Down
19 changes: 18 additions & 1 deletion src/phaethon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
* The project's main entry point.
*/

#include "src/common/platform.h"

#ifdef WIN32
#include <windows.h>
#endif

#include <cstdio>

#include <QApplication>
Expand All @@ -31,7 +37,6 @@
#include "src/common/util.h"
#include "src/common/error.h"
#include "src/common/ustring.h"
#include "src/common/platform.h"

#include "src/gui/mainwindow.h"

Expand Down Expand Up @@ -154,3 +159,15 @@ void Phaethon::deinitSubsystems() {
void openGamePath(const Common::UString &path) {
Phaethon phaethon(path);
}

#ifdef WIN32
#ifdef UNICODE
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
return main(0, 0);
}
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) {
return main(0, 0);
}
#endif
#endif

0 comments on commit 7854a93

Please sign in to comment.