Sign in to follow this  
azherdev

[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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by azherdev
Thank 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 this post


Link to post
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;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this