From 9ff92aeb406506c14ec540f297ae95bf885ff1d5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 25 Jan 2021 13:36:01 +0100 Subject: [PATCH] Add hacky way to get console output back on windows --- source/window.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/window.cpp b/source/window.cpp index 9dceb8324..4ea0898eb 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -17,6 +17,10 @@ #include #include +#if defined(OS_WINDOWS) + #include +#endif + namespace hex { constexpr auto MenuBarItems = { "File", "Edit", "View", "Help" }; @@ -48,6 +52,21 @@ namespace hex { hex::SharedData::mainArgc = argc; hex::SharedData::mainArgv = argv; + // Try to attach to a currently open console on Windows if available + #if defined(OS_WINDOWS) + if (AttachConsole(ATTACH_PARENT_PROCESS)) { + HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (hStdOut != INVALID_HANDLE_VALUE) { + freopen("CONOUT$", "w", stdout); + freopen("CONERR$", "w", stderr); + setvbuf(stdout, nullptr, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); + } + } + #endif + + printf("Hello\n"); + ContentRegistry::Settings::load(); View::postEvent(Events::SettingsChanged);