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

来源:互联网 发布:MySQL删除重复记录 编辑:程序博客网 时间:2024/04/30 11:24
#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 app  AllocConsole();  // 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 );}
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);    }}
http://stackoverflow.com/questions/3009042/how-to-view-printf-output-in-win32-app-on-visual-studio-2010
原创粉丝点击