views:

1230

answers:

4

I want to use the TRACE() macro to get output in the debug window in VS2005 in a non mfc c++ project.

But I don't know which additional header or lib is needed.

I want to know are there any ways of putting messages in the debug output window and how can i do that, thx a lot

+2  A: 

You can try the DebugOutputString function. TRACE is only enabled in debug builds.

Fredrik Jansson
+2  A: 

If you use ATL you can try ATLTRACE.

TRACE is defined in afx.h as (at least in vs 2008):

// extern ATL::CTrace TRACE;
#define TRACE ATLTRACE

And ATLTRACE can be found in atltrace.h

Ulf Lindback
+3  A: 

Build your own.

trace.cpp:

#ifdef _DEBUG
bool _trace(TCHAR *format, ...)
{
   TCHAR buffer[1000];

   va_list argptr;
   va_start(argptr, format);
   wvsprintf(buffer, format, argptr);
   va_end(argptr);

   OutputDebugString(buffer);

   return true;
}
#endif

trace.h:

#include <windows.h>
#ifdef _DEBUG
bool _trace(TCHAR *format, ...);
#define TRACE _trace
#else
#define TRACE false && _trace
#endif

then just #include "trace.h" and you're all set.

Disclaimer: I just copy/pasted this code from a personal project and took out some project specific stuff, but there's no reason it shouldn't work. ;-)

Ferruccio
+1  A: 

In my understanding wvsprintf has problem with formatting. Use _vsnprintf (or thcar version _vsntprintf ) instead

Sarath