How can you view printf output in a Win32 application (entering with a WinMain) in Visual Studio 2010?
Thanks torak for your answer. It helped me a lot.
I needed a bigger scroll back buffer so made a few additions after taking a look at the API functions. Shared here in case it helps anybody else:
void SetStdOutToNewConsole()
{
// allocate a console for this app
AllocConsole();
// redirect unbuffered STDOUT to the console
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT);
FILE *fp = _fdopen( fileDescriptor, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// give the console window a nicer title
SetConsoleTitle(L"Debug Output");
// give the console window a bigger buffer size
CONSOLE_SCREEN_BUFFER_INFO csbi;
if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) )
{
COORD bufferSize;
bufferSize.X = csbi.dwSize.X;
bufferSize.Y = 9999;
SetConsoleScreenBufferSize(consoleHandle, bufferSize);
}
}
This increases the scroll back (screen buffer) height to 9999 lines.
Tested on Windows XP and Windows 7.