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
相关文章推荐
- buildconfigurationHow to use Boost in Visual Studio 2010
- Visual Studio: How to change ipch path in Visual Studio 2010 (.sdf, *.opensdf, ...)
- How to get Intellisense for Web.config and App.config in Visual Studio .NET?(转载)
- How to use Boost in Visual Studio 2010
- How to build mex file directly in Visual Studio 2010?
- How To Set Dark Theme in Visual Studio 2010
- How to embed Lua in C++ on Visual Studio
- How to read out WhatsApp messages with Tasker and react on their content in real time
- [c#] where to see console.write output in visual studio?
- How to debug test code on Windows Mobile Emulator with Visual Studio
- How to use Intel C++ Compiler in Visual Studio 2008
- how to open property manager in Visual C++ 2010 express edition
- How to Install MS Visual Studio Code in Ubuntu 16.04/16.10
- How To Install Help Files Locally Of Visual Studio 2010
- How to fix compatibility mode error that can appear when installing Windows Phone Developer Tools or Visual Studio 2010
- CodeFluent Entities: How to add intellisense into Parts XML development in Visual Studio ?
- Instruments on Leopard: How to debug those random crashes in your Cocoa app
- How can I do a parallel build in Visual Studio 2010?
- How to debug release mode program in visual studio
- How To Compile Qt with Visual Studio 2010