【问题标题】:Getting rid of atlTraceGeneral category shown in ATLTRACE output摆脱 ATLTRACE 输出中显示的 atlTraceGeneral 类别
【发布时间】:2013-12-28 18:34:06
【问题描述】:

升级到 VS2013 后,我开始以“():atlTraceGeneral - 我的输出”格式接收所有 ATLTRACE2 消息。

例如

ATLTRACE(_T("This is my data: %d\n"), 124);

...显示为

dllmain.cpp(1121) : atlTraceGeneral - This is my data: 124

我不需要任何其他信息。这里有什么方法可以恢复到以前的格式,这样输出就可以了

This is my data: 124

【问题讨论】:

  • 据说,您可以使用 ATL/MFC Trace Tool 禁用“Category and Fucntion Name”跟踪。如果这以交互方式有效,您也可以在代码中以编程方式执行相同的操作 - 更新应用的初始状态。
  • 我在当前示例中找不到 ATL/MFC 跟踪工具。
  • VS 2012 在C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\AtlTraceTool8.exe 中有它,想必VS 2013 也有它。它也可以从 IDE,从菜单工具启动。
  • 感谢您指出该工具。我不知道现在它已包含在 VS 工具中。但是,它只为 VS2012 管理 ATL,而不是 VS2013,我需要在 VS2013 中修复
  • 这是核心问题,该工具在VS2013中被删除。除此之外,还有任何抑制无关喋喋不休的选项。

标签: c++ visual-studio-2013 atl


【解决方案1】:

唯一可行的解​​决方法是在 _DEBUG 宏下取消定义 ATLTRACE 并自行实现跟踪。微软的人推荐the same

解决方案如下:

#ifdef _DEBUG
#ifdef ATLTRACE 
#undef ATLTRACE
#undef ATLTRACE2

#define ATLTRACE CustomTrace
#define ATLTRACE2 ATLTRACE
#endif // ATLTRACE
#endif // _DEBUG

使用以下 CustomTrace:

void CustomTrace(const wchar_t* format, ...)
{
    const int TraceBufferSize = 1024;
    wchar_t buffer[TraceBufferSize];

    va_list argptr; va_start(argptr, format);
    vswprintf_s(buffer, format, argptr);
    va_end(argptr);

    ::OutputDebugString(buffer);
}

void CustomTrace(int dwCategory, int line, const wchar_t* format, ...)
{
    va_list argptr; va_start(argptr, format);
    CustomTrace(format, argptr);
    va_end(argptr);
}

【讨论】:

  • 我相信倒数第二行应该是CustomTrace(...而不是Hooktrace(...
  • @Anton,谢谢它的帮助。我虽然有一些带有 ATLTRACE 的神奇代码,但实际上没有。
【解决方案2】:

我走了一条不同的路线——我选择像这样编辑输出(消息只会变短,因此不需要分配):

#ifdef _DEBUG
static int __cdecl crtReportHookW(int nReportType, wchar_t* wszMsg, int* pnRet)
{
    const wchar_t wszTrace[] = L"atlTraceGeneral - ";
    const int ccTrace = _countof(wszTrace) - 1;         // exclude L'\0'
    if (nReportType == _CRT_WARN)
    {
        wchar_t* pwsz = wcsstr(wszMsg, wszTrace);
        if (pwsz != nullptr)
        {
            int ccBuf = wcslen(pwsz) + 1;       // remaining buffer size (include L'\0')
            wmemmove_s(pwsz, ccBuf, &pwsz[ccTrace], ccBuf - ccTrace);
        }
    }
    return FALSE;       // always keep processing
}
#endif

在 CWinApp 派生的构造函数中:

#ifdef _DEBUG
    _CrtSetReportHookW2(_CRT_RPTHOOK_INSTALL, crtReportHookW);
#endif

和 CWinApp 派生的析构函数:

#ifdef _DEBUG
    _CrtSetReportHookW2(_CRT_RPTHOOK_REMOVE, crtReportHookW);
#endif

由于某种原因,MCBS 和宽字符版本的挂钩都使用相同的消息调用,因此即使在 MBCS 应用程序中也只需要宽字符挂钩。

【讨论】:

    猜你喜欢
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 2012-10-30
    • 2017-02-15
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    相关资源
    最近更新 更多