轉自:http://blog.chinaunix.net/u3/94302/showart_1891797.html
1,使用OutputDebugString在win32程序中可以使用函數OutputDebugString輸出調試信息。輸出的結果可以在vs的集成環境中看到,也可以使用工具DbgView.exe捕捉結果。函數的原形如下: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
因為OutputDebugString的參數是字符串,而我們在實際使用過程中希望能像printf一樣支持變參。可以用下面的方法實現這個效果:
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