1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 16:49:55 +00:00
openmw-tes3mp/components/debug/win32.cpp
2018-12-12 00:02:09 +01:00

43 lines
789 B
C++

#ifdef _WIN32
#include "win32.hpp"
#undef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <windows.h>
namespace Debug {
bool attachParentConsole()
{
if (GetConsoleWindow() != nullptr)
return true;
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
fflush(stdout);
fflush(stderr);
std::cout.flush();
std::cerr.flush();
// this looks dubious but is really the right way
_wfreopen(L"CON", L"w", stdout);
_wfreopen(L"CON", L"w", stderr);
_wfreopen(L"CON", L"r", stdin);
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
freopen("CON", "r", stdin);
return true;
}
return false;
}
} // ns Debug
#endif