diff --git a/NativeApp/src/Win32/WinMain.cpp b/NativeApp/src/Win32/WinMain.cpp index 69b6e0c0..a7a1974e 100644 --- a/NativeApp/src/Win32/WinMain.cpp +++ b/NativeApp/src/Win32/WinMain.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,6 +55,18 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif + BOOL ConsoleAttached = AttachConsole(ATTACH_PARENT_PROCESS); + + FILE* pConOut = nullptr; + FILE* pConErr = nullptr; + FILE* pConIn = nullptr; + if (ConsoleAttached) + { + freopen_s(&pConOut, "CONOUT$", "w", stdout); + freopen_s(&pConErr, "CONOUT$", "w", stderr); + freopen_s(&pConIn, "CONIN$", "r", stdin); + } + g_pTheApp.reset(CreateApplication()); const auto* CmdLine = GetCommandLineA(); @@ -166,6 +178,24 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, g_pTheApp.reset(); + if (ConsoleAttached) + { + if (pConOut) + { + fflush(stdout); + fclose(pConOut); + } + if (pConErr) + { + fflush(stderr); + fclose(pConErr); + } + if (pConIn) + fclose(pConIn); + + FreeConsole(); + } + return (int)msg.wParam; }