if (NULL == pObj)
{
    OutputDebugString(L"here"); // 这是一个通常不会经过的地方,但我想做个“路标”给它
    return;
}// do others.../*
here能够在debugger栏看到。表示程序运行时,在特定条件下,pObj为零。
但是,OutputDebugString(L"here")代码,在Debug/Release下都有译码的。问题一:其调试时,有个debugger栏给它输出;但点击exe,它又输出到哪呢?问题二:发布代码时,不想有译码,有个办法就是
#ifdef _DEBUG
    OutputDebugString(L"here");
#endif
这意味着,我必须在每个here/there的输出地,添加if/endif。
有没有更简略的办法?
*/

解决方案 »

  1.   

    问题一:OutputDebugString只能在IDE中看到,要想实际运行的时候有路标,就弄一个log记录吧.
    问题重写一个输出函数,每次输出的时候使用新函数MyOutputDebugString
    例如:MyOutputDebugString(LPCTSTR lpOutputString )
    {
    #ifdef _DEBUG
        OutputDebugString(lpOutputString );
    #endif
    }
      

  2.   

    自己使用一个Log module好了,打印对应的log日志文件,当不想打印时修改一个标志位等,就打印文件了
      

  3.   

    问题一:其调试时,有个debugger栏给它输出;但点击exe,它又输出到哪呢?
    可以用dbgview这个工具查看问题二:#ifdef _DEBUG
    #define MyOutputDebugString(x) OutputDebugString(x)
    #else
    #define MyOutputDebugString(x)
    #endif然后用MyOutputDebugString这个宏就行了