diff --git a/Source/Engine/Main/Windows/main.cpp b/Source/Engine/Main/Windows/main.cpp index b60f6d2c5..7f8aa872a 100644 --- a/Source/Engine/Main/Windows/main.cpp +++ b/Source/Engine/Main/Windows/main.cpp @@ -27,7 +27,7 @@ __declspec(dllexport) int32 AmdPowerXpressRequestHighPerformance = 1; extern LONG CALLBACK SehExceptionHandler(EXCEPTION_POINTERS* ep); -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow) +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #ifdef USE_VS_MEM_LEAKS_CHECK // Memory leaks detect inside VS diff --git a/Source/Engine/Platform/Win32/Win32Platform.cpp b/Source/Engine/Platform/Win32/Win32Platform.cpp index 3bf261fa6..31c0f4a36 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.cpp +++ b/Source/Engine/Platform/Win32/Win32Platform.cpp @@ -10,6 +10,7 @@ #include "Engine/Core/Math/Math.h" #include "Engine/Core/Collections/HashFunctions.h" #include "Engine/Core/Log.h" +#include "Engine/Engine/CommandLine.h" #include "IncludeWindowsHeaders.h" #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #pragma comment(lib, "Iphlpapi.lib") namespace @@ -63,6 +65,28 @@ bool Win32Platform::Init() if (PlatformBase::Init()) return true; + // Init console output (engine is linked with /SUBSYSTEM:WINDOWS so it lacks of proper console output on Windows) + if (CommandLine::Options.Std) + { + // Attaches output of application to parent console, returns true if running in console-mode + // [Reference: https://www.tillett.info/2013/05/13/how-to-create-a-windows-program-that-works-as-both-as-a-gui-and-console-application] + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + const HANDLE consoleHandleOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (consoleHandleOut != INVALID_HANDLE_VALUE) + { + freopen("CONOUT$", "w", stdout); + setvbuf(stdout, NULL, _IONBF, 0); + } + const HANDLE consoleHandleError = GetStdHandle(STD_ERROR_HANDLE); + if (consoleHandleError != INVALID_HANDLE_VALUE) + { + freopen("CONOUT$", "w", stderr); + setvbuf(stderr, NULL, _IONBF, 0); + } + } + } + // Init timing LARGE_INTEGER frequency; const auto freqResult = QueryPerformanceFrequency(&frequency);