How to enable the TRACE macro in Release mode?(如何在 Release 模式下启用 TRACE 宏?)
问题描述
TRACE 宏 可用于在 Debug 模式下编译代码时向调试器输出诊断消息.我在 Release 模式下需要相同的消息.有没有办法做到这一点?
The TRACE macro can be used to output diagnostic messages to the debugger when the code is compiled in Debug mode. I need the same messages while in Release mode. Is there a way to achieve this?
(请不要浪费您的时间讨论为什么我不应该在发布模式下使用 TRACE :-)
(Please do not waste your time discussing why I should not be using TRACE in Release mode :-)
推荐答案
其实TRACE宏比OutputDebugString灵活很多.它需要一个 printf() 样式的格式字符串和参数列表,而 OutputDebugString 只需要一个字符串.为了在发布模式下实现完整的 TRACE 功能,您需要执行以下操作:
Actually, the TRACE macro is a lot more flexible than OutputDebugString. It takes a printf() style format string and parameter list whereas OutputDebugString just takes a single string. In order to implement the full TRACE functionality in release mode you need to do something like this:
void trace(const char* format, ...)
{
char buffer[1000];
va_list argptr;
va_start(argptr, format);
wvsprintf(buffer, format, argptr);
va_end(argptr);
OutputDebugString(buffer);
}
这篇关于如何在 Release 模式下启用 TRACE 宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Release 模式下启用 TRACE 宏?
基础教程推荐
- 提升 ASIO 流缓冲 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
