您的位置:首页 > 移动开发

how to view printf output in win32 app on visual studio 2010?

2013-04-15 13:26 651 查看
#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
{
int number = 10;

char str[256];

sprintf_s(str, "It works! - number: %d \n", number);

OutputDebugString(str);

return 0;
}
void SetStdOutToNewConsole(){int hConHandle;long lStdHandle;FILE *fp;// allocate a console for this appAllocConsole();// redirect unbuffered STDOUT to the consolelStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);fp = _fdopen( hConHandle, "w" );*stdout = *fp;setvbuf( stdout, NULL, _IONBF, 0 );}
void SetStdOutToNewConsole(){// allocate a console for this appAllocConsole();// redirect unbuffered STDOUT to the consoleHANDLE 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 titleSetConsoleTitle(L"Debug Output");// give the console window a bigger buffer sizeCONSOLE_SCREEN_BUFFER_INFO csbi;if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) ){COORD bufferSize;bufferSize.X = csbi.dwSize.X;bufferSize.Y = 9999;SetConsoleScreenBufferSize(consoleHandle, bufferSize);}}
http://stackoverflow.com/questions/3009042/how-to-view-printf-output-in-win32-app-on-visual-studio-2010
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: