How can I use TRACE, ASSERT, VERIFY macro in non mfc projects

Build your own TRACE() macro to get output in the debug window in Visual Studio in a non MFC C++ project.

// debugging.h
#ifdef _DEBUG
bool _trace(TCHAR *format, ...);
#define TRACE _trace
#define ASSERT(x) {if(!(x)) _asm{int 0x03}}
#define VERIFY(x) {if(!(x)) _asm{int 0x03}}
#else
#define TRACE false && _trace
#define ASSERT(x)
#define VERIFY(x) x
#endif
// debugging.cpp
#include "StdAfx.h"
#include "Debugging.h"

#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

Related Posts