How to enable the TRACE macro in Release mode?

Ashwin Nanjappa picture Ashwin Nanjappa · Aug 26, 2008 · Viewed 14.3k times · Source

The TRACE macro can be used to output diagnostic messages to the debugger when the code is compiled in Debug mode. I need the same messages while in Release mode. Is there a way to achieve this?

(Please do not waste your time discussing why I should not be using TRACE in Release mode :-)

Answer

Ferruccio picture Ferruccio · Sep 3, 2008

Actually, the TRACE macro is a lot more flexible than OutputDebugString. It takes a printf() style format string and parameter list whereas OutputDebugString just takes a single string. In order to implement the full TRACE functionality in release mode you need to do something like this:

void trace(const char* format, ...)
{
   char buffer[1000];

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

   OutputDebugString(buffer);
}