Skip to content

Commit

Permalink
NativeAppBase: added console output on Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets committed Aug 14, 2024
1 parent 7ef6821 commit 64fa5a3
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion NativeApp/src/Win32/WinMain.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 64fa5a3

Please sign in to comment.