3. Implementation/Windows API

Win32에서 TRACE 매크로 문

SSKK 2008. 8. 20. 11:27
아래 코드를 추가하면 Win32에서도 MFC에서 사용하는 TRACE를 똑같이 사용할 수 있다.
주의할점은 버퍼 사이즈 제한이 있다는 점.

#ifndef TRACE
#include <strsafe.h>
#include <assert.h>
#if defined(_DEBUG) || defined(FORCE_XTRACE)
#define TRACE_BUF_SIZE 4096
#define TRACE          _DbgPrintf
#ifndef ASSERT
#define ASSERT   assert
#endif
inline void __cdecl _DbgPrintf(LPCTSTR str, ...)
{
 TCHAR   buff[TRACE_BUF_SIZE];
 DWORD   dwError;
 va_list    ap;
 dwError = GetLastError();
 va_start(ap, str);
 StringCbVPrintf(buff, sizeof buff, str, ap);
 va_end(ap);
 OutputDebugString(buff);
 SetLastError(dwError);   
}
#else
#define TRACE 1 ? (void) 0 : _DbgPrintf
inline void _DbgPrintf(const char *str, ...) {}
#endif
#endif