| 以前写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,然后看输出,可以过滤输出和保存日志的。 |