我的WPF应用程序使用第三方Win32 dll通过OutputDebugString记录消息。
我可以在Visual或通过OutputDebugString中看到DebugView消息,但我不想要求我的客户运行DebugView。我想捕获来自OutputDebugString的消息并自动将它们记录到一个文件中,所以如果客户有问题,我可以让她给我发送日志文件。
这个是可能的吗?或者用户必须启动DebugView,复制错误,然后以这种方式发送日志给我吗?
发布于 2014-06-20 07:30:22
钩子OutputDebugStringW.为此,我建议使用绕道库。
#include <windows.h>
#include <detours.h>
#pragma comment(lib, "detours.lib")
BOOL SetHook(__in BOOL bState, __inout PVOID* ppPointer, __in PVOID pDetour)
{
if (DetourTransactionBegin() == NO_ERROR)
if (DetourUpdateThread(GetCurrentThread()) == NO_ERROR)
if ((bState ? DetourAttach : DetourDetach)(ppPointer, pDetour) == NO_ERROR)
if (DetourTransactionCommit() == NO_ERROR)
return TRUE;
return FALSE;
{
#define InstallHook(x, y) SetHook(TRUE, x, y)
VOID (WINAPI * _OutputDebugStringW)(__in_z_opt LPCWSTR lpcszString) = OutputDebugStringW;
VOID WINAPI OutputDebugStringHook(__in_z_opt LPCWSTR lpcszString)
{
// do something with the string, like write to file
_OutputDebugStringW(lpcszString);
}
// somewhere in your code
InstallHook((PVOID*)&_OutputDebugStringW, OutputDebugStringHook);发布于 2014-06-20 05:55:03
@Cody的建议“编写您自己的调试侦听器,然后您基本上已经编写了一个低级的DebugView克隆”,这听起来可能实际上是对我问题的一个回答。
这是基本的C#捕获工具的OutputDebugString实现。我已经在谷歌上看过几次了,但是我的眼睛盯着它,假设“这不可能是我想要的,对吗?”结果,这可能就是我问题的答案。
https://stackoverflow.com/questions/24320665
复制相似问题