DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在win32程序中可以使用函数OutputDebugString输出调试信息。输出的结果可以在vs的集成环境中看到,也可以使用工具DbgView.exe捕捉结果。函数的原形如下:

OutputDebugString

The 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);
}

posted on 2012-12-28 15:37  DoubleLi  阅读(2189)  评论(0编辑  收藏  举报