我在非托管 C++ DLL 中有以下代码。ToasterHook() 函数由使用 P/Invoke 的 C# 应用程序调用,并且 WndProc 被覆盖以捕获任何 WM_COPYDATA 消息。Process Explorer 说我的 DLL 已被注入到其他进程中,但是当我的表单加载时,我只收到 WM_COPYDATA 一次。
#pragma data_seg (".SHARED")
HHOOK g_HookHandle = 0;
HINSTANCE DllHandle;
HOOKPROC hkprcSysMsg;
#pragma data_seg()
extern "C" __declspec(dllexport) int ToasterHook()
{
if(g_HookHandle != 0) return 0;
DllHandle = LoadLibrary(L"toasterHookDll.dll");
hkprcSysMsg = (HOOKPROC)GetProcAddress(DllHandle, "_ToasterInterProcFilter@12");
g_HookHandle = SetWindowsHookEx(WH_SHELL, hkprcSysMsg, DllHandle, 0);
return 0;
}
extern "C" __declspec(dllexport)
LRESULT CALLBACK ToasterInterProcFilter(int code, WPARAM wParam, LPARAM lParam)
{
if(code == HSHELL_WINDOWCREATED) {
HWND g_ToasterReceiver = FindWindow(NULL, L"toaster");
SendNotifyMessage(g_ToasterReceiver, WM_COPYDATA, wParam, lParam);
}
return CallNextHookEx(g_HookHandle, code, wParam, lParam);
}
extern "C" __declspec(dllexport) void ToasterUnHook()
{
if(g_HookHandle == 0) return;
UnhookWindowsHookEx(g_HookHandle);
}
我在这里做错了什么?为 HOOKPROC指定GetProcAddress(DllHandle, "_ToasterInterProcFilter@12")
norToasterInterProcFilter
本身的结果似乎有效。