Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined(AK_OS_WINDOWS)
- //Attempt to attach to parent
- if(!AttachConsole(ATTACH_PARENT_PROCESS)) {
- if(!force)
- return false;
- //Try to create a new window, if allowed
- FreeConsole();
- if(!AllocConsole())
- return false;
- SetConsoleTitle(L"Debug Console");
- }
- //The std stream are reopen using the console handle
- freopen("CONOUT$", "w", stdout);
- freopen("CONIN$", "r", stdin);
- freopen("CONERR$", "w", stderr);
- //make sure the console handles are returned by GetStdHandle
- HANDLE newOut = CreateFileW(L"CONOUT$", GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
- SetStdHandle(STD_OUTPUT_HANDLE, newOut);
- HANDLE newErr = CreateFileW(L"CONERR$", GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
- SetStdHandle(STD_ERROR_HANDLE, newErr);
- //clear the std stream state to make sure they are not in an error state
- std::wcout.clear();
- std::cout.clear();
- std::wcerr.clear();
- std::cerr.clear();
- std::wcin.clear();
- std::cin.clear();
- //pprint should recalculate the capabilities of the newly attached console
- gWInConsoleInitialized = false;
- return true;
- #endif
- return isTerminal();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement