本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9727774
建立时间:2004年12月20日




[c++]调试信息的输出DebugView的使用
原创空间,  软件技术,  电脑与网络

邢红瑞 发表于 2005/11/8 9:42:22

 以前写vxd的时候,多亏有了debugprint,要不然不知道程序执行到哪里了。debugview也是类似的一个工具,其实vc的TRACE很难用,首先必须在调试环境下运行,再者必须是MFC的工程,最后是所有的信息输出在一起,难以过滤。先建立一个.h文件加入3行#include <stdlib.h>#include <stdio.h>#include <stdarg.h>声明一个宏//DT is a macro to help debug app by dump useful info, //it works for debug and release version.//usage://DT("work ok in line %d",m_nLine); //define following line to enable DT#define DT DebugTrace//uncomment following line to disable DT//#undef DT//#define DT定义函数,最好是inlineBOOL DebugTrace(char * lpszFormat,...){ static HWND hwnd = ::FindWindowA(NULL, "DbgView"); if(!IsWindow(hwnd))  hwnd = ::FindWindowA(NULL, "DbgView"); if(hwnd) {  static char szMsg[512];   va_list argList;  va_start(argList, lpszFormat);  try  {   vsprintf(szMsg,lpszFormat, argList);  }  catch(...)  {   strcpy(szMsg ,"DebugHelper:Invalid string format!");  }  va_end(argList);  DWORD dwId = GetCurrentProcessId();  ::SendMessage(hwnd,WM_SETTEXT,dwId,(LPARAM)(LPCTSTR)szMsg);//  ::PostMessage(hwnd,WM_SETTEXT,dwId,(LPARAM)(LPCTSTR)szMsg); } return TRUE;}运行前,先打来debugview,然后看输出,可以过滤输出和保存日志的。


阅读全文(11069) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.203 second(s), page refreshed 144832939 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号