Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #if defined(AK_OS_WINDOWS)
  2. //Attempt to attach to parent
  3. if(!AttachConsole(ATTACH_PARENT_PROCESS)) {
  4. if(!force)
  5. return false;
  6. //Try to create a new window, if allowed
  7. FreeConsole();
  8. if(!AllocConsole())
  9. return false;
  10. SetConsoleTitle(L"Debug Console");
  11. }
  12. //The std stream are reopen using the console handle
  13. freopen("CONOUT$", "w", stdout);
  14. freopen("CONIN$", "r", stdin);
  15. freopen("CONERR$", "w", stderr);
  16.  
  17. //make sure the console handles are returned by GetStdHandle
  18. HANDLE newOut = CreateFileW(L"CONOUT$", GENERIC_WRITE | GENERIC_READ,
  19. FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
  20. SetStdHandle(STD_OUTPUT_HANDLE, newOut);
  21.  
  22. HANDLE newErr = CreateFileW(L"CONERR$", GENERIC_WRITE | GENERIC_READ,
  23. FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
  24. SetStdHandle(STD_ERROR_HANDLE, newErr);
  25.  
  26. //clear the std stream state to make sure they are not in an error state
  27. std::wcout.clear();
  28. std::cout.clear();
  29. std::wcerr.clear();
  30. std::cerr.clear();
  31. std::wcin.clear();
  32. std::cin.clear();
  33.  
  34. //pprint should recalculate the capabilities of the newly attached console
  35. gWInConsoleInitialized = false;
  36. return true;
  37.  
  38. #endif
  39. return isTerminal();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement