轉(zhuǎn)自:http://blog.chinaunix.net/u3/94302/showart_1891797.html
1,使用OutputDebugString在win32程序中可以使用函數(shù)OutputDebugString輸出調(diào)試信息。輸出的結(jié)果可以在vs的集成環(huán)境中看到,也可以使用工具DbgView.exe捕捉結(jié)果。函數(shù)的原形如下:OutputDebugStringThe OutputDebugString function sends a string to the debugger for display.void OutputDebugString(
LPCTSTR lpOutputString
);
Parameters
lpOutputString
[in] Pointer to the null-terminated string to be displayed.
Return Values
This function does not return a value
因?yàn)镺utputDebugString的參數(shù)是字符串,而我們?cè)趯?shí)際使用過(guò)程中希望能像printf一樣支持變參。可以用下面的方法實(shí)現(xiàn)這個(gè)效果:
inline bool MyDbgStr(LPCSTR lpszFormat, ...)
{
va_list args;
int nBuf;
TCHAR szBuffer[512];
va_start(args, lpszFormat);
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer)*sizeof(TCHAR), lpszFormat, args);
Assert(nBuf > 0);
OutputDebugString(szBuffer);
va_end(args);
}
文章出處:
http://www.diybl.com/course/3_program/c++/cppsl/200866/122894.html