E D R , A S I H C RSS

Trace

MFC 에서 제공하는 ~cpp TRACE 매크로의 기능을 VC 의 다른 프로젝트에서도 사용할 수 있다. 단, 여기서는 매크로가 아니라 함수인것을 유념하자.
( ~cpp TRACE 매크로가 내부적으로 함수 호출을 하는것 같기는 한데 생각해보면 ~cpp TRACE 매크로보다 우리가 정의한 함수를 호출하는게 조금더 오버헤드가 있을것 같다 )

함수 body


~cpp 
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <crtdbg.h>
using namespace std;

#ifdef _DEBUG
#define TRACE Trace
#else
#define TRACE ;
#endif


void _cdecl Trace(LPCTSTR lpszFormat, ...)
{
	va_list args;
	int nBuf;
	TCHAR szBuffer[512];

	va_start(args, lpszFormat);
	nBuf = _vstprintf(szBuffer, lpszFormat, args);

	_ASSERT(nBuf < sizeof(szBuffer));
	//_tprintf(szBuffer);  // 이부분은 console window 에 출력해주는 부분이다.

	OutputDebugString(szBuffer); // debug output window 에 string 출력

	va_end(args);
}
 

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:15
Processing time 0.0107 sec