我正在维护一个 C++ COM 项目。有一些跟踪线,例如 ATLTRACE(message); 我搜索了 ATLTRACE。 MSDN 告诉 Visual C++ 输出窗口会显示它。但是,该产品是一个发行版。客户将没有源代码,也无法在 VS 中对其进行调试。那么有没有其他方便的查看方式呢? Windows 事件查看器会捕捉到吗?或者我必须更改代码? Win7、VS2013
最佳答案
ATLTRACE 仅使用调试输出,并且仅在调试版本中有效!
因此您可以为最终用户提供一个用于测试目的的调试版本,并使用来自 Sysinternals 的 DebugView。但这可能会很复杂,因为您还必须遍历不可重新分发的调试运行时。
但是您可以轻松编写自己的具有相同功能的 MY_TRACE 宏。
#define MY_TRACE GetMyTracer() // returns object of CMyTracer
...
class CMyTracer
{
...
// Helper operator to get the trace commands. They call the TraceV functions
void operator()(PCSTR pszFormat, ...);
void operator()(PCWSTR pszFormat, ...);
// Worker functions that do the real job calling TraceV functions
void Trace(PCSTR pszFormat, ...);
void Trace(PCWSTR pszFormat, ...);
// Allowed to be virtual to do some internal mystique stuff, like redirecting and this functions perform all output...
virtual void TraceV(PCSTR pszFormat, va_list args);
virtual void TraceV(PCWSTR pszFormat, va_list args);
...
现在您可以使用它代替 ATLTRACE
...
MYTRACE("Simple output\n");
MYTRACE("More complex output %d\n", 4711);
注意:用您自己的替换替换所有 ATLTRACE 宏是不明智的。如果不影响速度,您可以将跟踪输出分布到多个位置,但值得提供信息。
关于c++ - 我在哪里可以看到 ATLTRACE 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47585567/