[Win32 C++] How do I write to the "Output" window in Visual Studio 2005?

Recommended Posts

Ok, I am going crazy here. Does anyone know how to write a string to the "Output" window in Visual Studio 2005 C++ Win32 project? Not using ATL. Thank you folks.

Share on other sites
OutputDebugString as I remember.

Share on other sites
The function OutputDebugString does that for you.
Note that it does not accept a printf-like formatting, so you need to pass whole strings to it.

Share on other sites
Thank you guys. But what about this TRACE macro? Where is it defined? Does the OutputDebugString go away in the release build?

Share on other sites
Here's OutputDebugString in MSDN:

http://msdn2.microsoft.com/en-us/library/aa363362.aspx

says nothing about debug/release, so assume it shows up in all builds.

MSDN seems to be silent on the TRACE macro. Either grep (findstr) in the headers for that macro to see what it does, or write your own macro that does what you want.

Good luck,
Geoff

Share on other sites
TRACE is an MFC macro and it does the same thing as OutputDebugString except you can use printf style formatting.

I'm fairly certain these functions only work in debug builds.

Share on other sites
Cool, thanks guys. I will then stick to OutputDebugString.

Share on other sites
Quote:
 Original post by azherdevThank you guys. But what about this TRACE macro? Where is it defined? Does the OutputDebugString go away in the release build?
Right click on TRACE in MSVC and click "Go to definition". It's probably a function that calls OutputDebugString.

From my code:
#include <windows.h>#include <stdio.h>void PLog::DebugFormat(const char* szFormat, ...){	char szBuff[1024];	va_list arg;	va_start(arg, szFormat);	_vsnprintf(szBuff, sizeof(szBuff), szFormat, arg);	va_end(arg);	OutputDebugString(szBuff);}

And OutputDebugString() does not go away in Release builds, you'll have to wrap it in a macro to do that. Random fact: GTA2 is actually compiled with a few OutputDebugStrings in it. At least they show up in the function import table.

Share on other sites
Also, if you are writing code for a CObject derivative class, you can used the CDumpContext reference 'afxDump' ie afxDump << "Going to debug window" << this;

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627636
• Total Posts
2978331

• 10
• 12
• 22
• 13
• 33