我正在爲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