我正在为WH_GETMESSAGE写入全局钩子。但是,当从dll调用GetProcAddress函数时,我得到错误代码127,即ERROR_PROC_NOT_FOUND。它无法找到GetMsgProc。任何想法为什么?调用GetProcAddress时出现错误127
此外,我是这种编程的新手,所以对任何错误都不抱歉。
DLL文件:
#include "windows.h"
#include <stdio.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
__declspec(dllexport) LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, TEXT("I am in"),TEXT("In a DLL"), MB_OK);
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
程序加载的DLL文件:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
typedef LRESULT(CALLBACK *LPGetMsgProc)(int nCode, WPARAM wParam, LPARAM lParam);
int main()
{
HMODULE hDll = LoadLibrary(_T("../../dllTouchInputHook/x64/Debug/dllTouchInputHook.dll"));
LPGetMsgProc proc = (LPGetMsgProc)GetProcAddress(hDll, "GetMsgProc");
if (proc == NULL) {
printf("The error code is %d", GetLastError());
}
HHOOK hMsgHook = SetWindowsHookEx(WH_GETMESSAGE, proc, hDll, 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hMsgHook);
return 0;
}
你没有检查从'LoadLibrary'结果。 –
当然它没有找到'GetMsgProc',因为它没有以这个名字出口。 – RbMm
@DanielSęk:我检查了LoadLibrary的结果。它不是空的 – Roger1990