Original Post
🔒 Locked
Console window for debugging with a window app?
Advertisement
Yes, this is possible. ALl you need to do is change the 'subsystem' of your project. This can be done in project settings or you can use this:
Here's an image as proof [grin]
- Drew
#pragma comment(linker, "/subsystem:\"console\" /entry:\"WinMainCRTStartup\"")Here's an image as proof [grin]
- Drew
I usually like using the subsystem method, but if you would also like all the STD streams routed to that console, here is some code to do that for you.
This will bind cin, cout, cerr, printf, etc to the newly allocated console.
This will bind cin, cout, cerr, printf, etc to the newly allocated console.
void CreateConsoleLog(const char *winTitle){ AllocConsole(); SetConsoleTitle(winTitle); int hConHandle; long lStdHandle; FILE *fp; // redirect unbuffered STDOUT to the console lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stdout = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); // redirect unbuffered STDIN to the console lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "r" ); *stdin = *fp; setvbuf( stdin, NULL, _IONBF, 0 ); // redirect unbuffered STDERR to the console lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stderr = *fp; setvbuf( stderr, NULL, _IONBF, 0 );}Quote:
Original post by mfawcett
I usually like using the subsystem method, but if you would also like all the STD streams routed to that console, here is some code to do that for you.
This will bind cin, cout, cerr, printf, etc to the newly allocated console.
*** Source Snippet Removed ***
What is the difference between that method and using the subsystem? Everything that is being routed to the allocated console *seems* to already be routed with the subsystem method. Here's another pic. Or, is it just the 'proper' way to do it? Just curious [smile]
Quote:The subsystem method forces you to have a log window when your application starts. Using AllocConsole() you can create the console at any time you want - for instance after you get into the actual game and not at the menu, or if you want it in debug mode only (although the subsystem method would be better suited in that case)
Original post by Drew_Benton
What is the difference between that method and using the subsystem? Everything that is being routed to the allocated console *seems* to already be routed with the subsystem method. Here's another pic. Or, is it just the 'proper' way to do it? Just curious [smile]
Quote:
Original post by Evil Steve
The subsystem method forces you to have a log window when your application starts. Using AllocConsole() you can create the console at any time you want - for instance after you get into the actual game and not at the menu, or if you want it in debug mode only (although the subsystem method would be better suited in that case)
Ohhh ok, thanks! Yes, I see now, more flexibility [smile].
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement