Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print to the debug output window in a Win32 app?

I've got a win32 project that I've loaded into Visual Studio 2005. I'd like to be able to print things to the Visual Studio output window, but I can't for the life of me work out how. I've tried 'printf' and 'cout <<' but my messages stay stubbornly unprinted.

Is there some sort of special way to print to the Visual Studio output window?

like image 394
izb Avatar asked Aug 26 '09 09:08

izb


People also ask

How do I show debug output?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.

What is debug output?

Debug Output is an OpenGL feature that makes debugging and optimizing OpenGL applications easier. Briefly, this feature provides a method for the driver to provide textual message information back to the application.


1 Answers

You can use OutputDebugString. OutputDebugString is a macro that depending on your build options either maps to OutputDebugStringA(char const*) or OutputDebugStringW(wchar_t const*). In the later case you will have to supply a wide character string to the function. To create a wide character literal you can use the L prefix:

OutputDebugStringW(L"My output string."); 

Normally you will use the macro version together with the _T macro like this:

OutputDebugString(_T("My output string.")); 

If you project is configured to build for UNICODE it will expand into:

OutputDebugStringW(L"My output string."); 

If you are not building for UNICODE it will expand into:

OutputDebugStringA("My output string."); 
like image 67
Martin Liversage Avatar answered Sep 20 '22 00:09

Martin Liversage