How can I use the TRACE macro in non-MFC projects?(如何在非 MFC 项目中使用 TRACE 宏?)
问题描述
我想使用 TRACE() 宏在 Visual Studio 的调试窗口中获取输出;2005 在一个非MFC C++ 项目中,但附加的头文件或库是需要吗?
I want to use the TRACE() macro to get output in the debug window in Visual Studio 2005 in a non-MFC C++ project, but which additional header or library is needed?
有没有办法在调试输出窗口中放置消息,我该怎么做?
Is there a way of putting messages in the debug output window and how can I do that?
推荐答案
构建您自己的方案.
trace.cpp:
#ifdef _DEBUG
bool _trace(TCHAR *format, ...)
{
TCHAR buffer[1000];
va_list argptr;
va_start(argptr, format);
wvsprintf(buffer, format, argptr);
va_end(argptr);
OutputDebugString(buffer);
return true;
}
#endif
trace.h:
#include <windows.h>
#ifdef _DEBUG
bool _trace(TCHAR *format, ...);
#define TRACE _trace
#else
#define TRACE false && _trace
#endif
然后只需 #include "trace.h" 就可以了.
then just #include "trace.h" and you're all set.
免责声明:我只是从个人项目中复制/粘贴了此代码并取出了一些特定于项目的内容,但没有理由它不起作用.;-)
Disclaimer: I just copy/pasted this code from a personal project and took out some project specific stuff, but there's no reason it shouldn't work. ;-)
这篇关于如何在非 MFC 项目中使用 TRACE 宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在非 MFC 项目中使用 TRACE 宏?


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07