windows下介绍一个简单的DebugView工具

来源:互联网 发布:联合石油数据库官网 编辑:程序博客网 时间:2024/06/04 17:44

在我们调试比较复杂的程序的时候,尤其是多个dll,多线程的情况下debug有时候不是很方便。debugview工具可以在我们需要的地方打下日志而且很方便实时的反应到界面上。

下载地址:http://technet.microsoft.com/en-us/sysinternals/bb896647

只需要使用windows API OutputDebugString就可以了。

Sends a string to the debugger for display.

Syntax

void WINAPI OutputDebugString(  __in_opt  LPCTSTR lpOutputString);

如下代码打印一个hello, world到DebugView界面上:

#include <Windows.h>int _tmain(int argc, _TCHAR* argv[]){OutputDebugString(L"hello, world");system("pause");return 0;}

注意运行程序的时候不能在vs上直接点运行,否则不能显示日志,需要使用:Ctrl+F5 Start without Debugging或者直接点击exe程序。

如果需要打印一些非字符串日志可以使用以下方式,根据窄字符和宽字符选择合适的OutputDebugString,默认是宽字符。

#include <Windows.h>#include <sstream>int _tmain(int argc, _TCHAR* argv[]){int num = 12345;std::stringstream ss;ss << "hello, world, " << num;OutputDebugStringA(ss.str().c_str());system("pause");return 0;}

显示界面如下:


一般我会禁用掉中间红色的两个叉叉,不然会捕获一些不必要的信息。


原创粉丝点击