windows 重写调试输出

// 使用OutputDebugString很不方便.不能自定义格式化输出.所以重写了一下.

#include <tchar.h>
#include <windows.h>


void __cdecl MyOutputDebugStrig(const _TCHAR* pszFormat, ...)
{
	_TCHAR buf[1024] = { 0 };
	// ZeroMemory( buf, 1024*sizeof(TCHAR ) );
	swprintf_s(buf, 1024, _T("线程ID = [%lu]"), GetCurrentThreadId());
	va_list arglist;
	va_start(arglist, pszFormat);
	int nBuffSize = _tcslen(buf);
	vswprintf_s(&buf[nBuffSize], 1024 - nBuffSize, pszFormat, arglist);
	va_end(arglist);
	nBuffSize = _tcslen(buf);
	_tcscat_s(buf, 1024 - nBuffSize, _T("
"));
	OutputDebugString(buf);
}
注意,请使用UNICODE字符集.
原文地址:https://www.cnblogs.com/iBinary/p/10754737.html