使用ProcMon 输出调试信息
https://github.com/Wintellect/ProcMonDebugOutput
提供者
/*//
// Process Monitor Debug Output Header File
//
// History:
// - April 1, 2010 - Version 1.0 - John Robbins/Wintellect
// - Initial release
// - March 1, 2014 - Version 1.1 - John Robbins/Wintellect
// - Fixed an issue in DLL main where the handle could get close too
// soon.
// - Moved the project to VS 2013.
//
//*/#pragma once#ifdef __cplusplus
extern "C" {
#endif /*//// The defines that set up how the functions or classes are exported or// imported.//*/
#ifndef PROCMONDEBUGOUTPUT_DLLINTERFACE
#ifdef PROCMONDEBUGOUTPUT_EXPORTS
#define PROCMONDEBUGOUTPUT_DLLINTERFACE __declspec ( dllexport )
#else
#define PROCMONDEBUGOUTPUT_DLLINTERFACE __declspec ( dllimport )
#endif
#endif /*//// ProcMonDebugOutput// Sends a string to Process Monitor for display.//// Parameters:// pszOutputString// The null-terminated wide character string to be displayed.//// Return Values:// TRUE - The string was sent to Process Monitor.// FALSE - There was a problem sending the string to Process Monitor. To get// extended error information, call GetLastError to determine the// exact failure.//// Last Error Codes:// ERROR_INVALID_PARAMETER - The pszOutputString parameter is NULL.// ERROR_WRITE_FAULT - The Process Monitor driver is loaded but the// Process Monitor user mode portion is not running.// ERROR_BAD_DRIVER - The Process Monitor driver is not loaded.//*/PROCMONDEBUGOUTPUT_DLLINTERFACE_Success_(return == TRUE)BOOL __stdcall ProcMonDebugOutput(_In_z_ LPCWSTR pszOutputString);#ifdef __cplusplus
}
#endif #include "stdafx.h"
#include "ProcMonDebugOutput.h"#define FILE_DEVICE_PROCMON_LOG 0x00009535
#define IOCTL_EXTERNAL_LOG_DEBUGOUT (ULONG) CTL_CODE(FILE_DEVICE_PROCMON_LOG ,\0x81 ,\METHOD_BUFFERED ,\FILE_WRITE_ACCESS )// The global file handle to the Process Monitor device.
static HANDLE g_hDevice = INVALID_HANDLE_VALUE;// Anonymous namespace for private helpers
namespace {HANDLE OpenProcessMonitorLogger(){if (INVALID_HANDLE_VALUE == g_hDevice){// I'm attempting the open every time because the user could start // Process Monitor after their process.g_hDevice = ::CreateFile(L"\\\\.\\Global\\ProcmonDebugLogger",GENERIC_WRITE,FILE_SHARE_WRITE,nullptr,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,nullptr);}return g_hDevice;}void CloseProcessMonitorLogger(){if (INVALID_HANDLE_VALUE != g_hDevice){::CloseHandle(g_hDevice);g_hDevice = INVALID_HANDLE_VALUE;}}// Used to pass strings to legacy C APIs expecting a raw void* pointer.inline void* StringToPVoid(PCWSTR psz){return reinterpret_cast<void *>(const_cast<wchar_t*>(psz));}} // anonymous namespacePROCMONDEBUGOUTPUT_DLLINTERFACE _Success_(return == TRUE)
BOOL __stdcall ProcMonDebugOutput(_In_z_ LPCWSTR pszOutputString)
{BOOL bRet = FALSE;if (nullptr == pszOutputString){::SetLastError(ERROR_INVALID_PARAMETER);bRet = FALSE;}else{HANDLE hProcMon = OpenProcessMonitorLogger();if (INVALID_HANDLE_VALUE != hProcMon){DWORD iLen = static_cast<DWORD>(wcslen(pszOutputString) * sizeof (WCHAR));DWORD iOutLen = 0;bRet = ::DeviceIoControl(hProcMon,IOCTL_EXTERNAL_LOG_DEBUGOUT,StringToPVoid(pszOutputString),iLen,nullptr,0,&iOutLen,nullptr);if (FALSE == bRet){DWORD dwLastError = ::GetLastError();if (ERROR_INVALID_PARAMETER == dwLastError){// The driver is loaded but the user mode Process Monitor// program is not running so turn the last error into a // write failure.::SetLastError(ERROR_WRITE_FAULT);}}}else{// Process Monitor isn't loaded.::SetLastError(ERROR_BAD_DRIVER);bRet = FALSE;}}return bRet;
}BOOL APIENTRY DllMain(HMODULE /*hModule*/,DWORD ul_reason_for_call,LPVOID /*lpReserved*/)
{switch (ul_reason_for_call){case DLL_PROCESS_ATTACH:case DLL_THREAD_ATTACH:case DLL_THREAD_DETACH:break;case DLL_PROCESS_DETACH:// Close the handle to the driver.CloseProcessMonitorLogger();break;}return TRUE;
}
使用方法:
int _tmain(void)
{WCHAR szText[100];for (int i = 0; i < 20; i++){_stprintf_s(szText,_countof(szText),L"ProcMon Debug Out Test # %d",i);BOOL bRet = ProcMonDebugOutput(szText);if (TRUE == bRet){_tprintf(L"Wrote %d\n", i);}else{_tprintf(L"error 0x%x\n", GetLastError());}::Sleep(500);}return (0);
}
ProcMon配置:
以上!
使用ProcMon 输出调试信息相关推荐
- 嵌入式开发输出调试信息的几种方法(常规法及非常规法)
这篇文章对于研发查找问题和测试都有很大帮助,在这里保存记录一下. 论语>有云:"工欲善其事,必先利其器".输出调试信息是软件开发中必不可少的调试利器,在出现bug时如果没有调 ...
- Qt 使用#define+qDebug()输出调试信息
/******************************************************************************************** Qt 使用# ...
- C++ MFC控制台输出调试信息
C++ MFC控制台输出调试信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1.#include <conio.h> 2.在需要开启控制台窗口的地方调用 ...
- 跟踪Makefile输出调试信息
/********************************************************************** 跟踪Makefile输出调试信息* 说明:* 有时候为了 ...
- C++ 输出调试信息 类似MFC的TRACE等宏
在MFC程序中有TRACE等一系列的宏可以输出调试信息, 但是其他的地方不能用了, 下面这个小程序测试了怎么输出调试信息, // Test_ErrorCode.cpp : 定义控制台应用程序的入口点. ...
- DebugView输出调试信息
在写windows程序时,需要输出一些调试信息,这里介绍一种极其方便的方法.即使用OutputDebugString 在Debug模式下输出调试信息,在Release模式下不输出. 我们可以在VS的集 ...
- 在MFC,Win32程序中向控制台(Console)窗口输出调试信息
在MFC程序中输出调试信息的方法有两种,一种是使用TRACE宏,可以向Output窗口输出调试信息:另一种是用MessageBox,弹出消息框来输出调试信息,但会影响程序的运行. 其实有一种方法可以更 ...
- php语法中可以输出调试信息,怎么优雅的输出PHP调试信息
如何优雅的输出PHP调试信息 经常因为出现紧急bug而被老板骂的同事,为了更快的修复而直接利用线上的错误环境现场debug,并直接在页面上echo和dump.结果被老板发现了,又是一通臭骂.那么有没有 ...
- OutputDebugString输出调试信息
OutputDebugString输出调试信息 声明 <windows.h>文件声明了 OutputDebugString() 函数的两个版本:一个用于 ASCII,一个用于 Unicod ...
最新文章
- QCustomPlot的简单用法总结
- html防止iOS将数字识别为电话号码
- Interface 的本质用处
- 【Python学习系列二十六】networkx库图最短路径求解
- 前端学习(2965):路由的参数传递
- object detection错误之no module named nets
- Altium AD20常用的操作快捷键,个人总结精炼版,全干货超实用
- python所有软件-python
- python怎么一次输入两个数_python如何一次性输入多个数
- storm 使用外部配置文件提交拓扑
- 登陆界面万能密码绕过
- Redis中key-value对value的数据类型
- 每天一道博弈论之“肥猫的游戏”
- 6.5编程实例-立方体透视投影
- IOS13图标尺寸_7大原则,带你设计出更优秀的图标
- Unity3D接入Android第三方SDK流程
- idea右侧maven依赖飘红解决办法
- 计算机无法安装蓝牙驱动,电脑没有蓝牙驱动怎么安装具体方法
- 【微信篇】PC端微信文件夹里的“微信号“
- 椭圆型变分问题理论及数值方法
热门文章
- ColBERT(2020SIGIR)
- 安卓手机+python基于abd命令的自动打卡
- catia v5r18 百度云_catia v5r18 64位免费版 附带安装教程
- hydd的Linux笔记Day47
- 今天遇到一个问题,就是用pycharm运行python程序,老是会出现Python.exe已停止的对话框。
- Python实现小说下载器,可以打包exe
- 计算机运行加减乘除哪个最慢,计算机算加减乘除的时间对比
- 【尚硅谷|韩顺平】数据结构和算法
- android 判断是白天还是晚上,然后设置地图模式
- Element日期选择器带快捷选项切换日期类型