나중에 SetWindowsHookEx() 함수를 사용하여 일부 프로세스에 삽입하려는 DLL을 빌드하려고합니다. 이상한 점은 DLL을로드하려고 할 때 GetProcAddress를 사용하여 그 안에 포함 된 프로 시저의 주소를 얻으려고하면 CBT 메시지 처리 절차의 주소를 얻으려고하면 NULL을 반환하지만 다른 기능들.GetProcAddress()를 사용하여 DLL에서 일부 함수를로드 할 수 없습니다.
이것은 코드입니다.
DLL HEADER (.H)
#include <windows.h>
extern "C" {
__declspec(dllexport) LRESULT CALLBACK hookProc(int code, WPARAM wParam, LPARAM lParam);
__declspec(dllexport) int add(int a, int b);
}
DLL 파일 (cpp를) 내가 GetL를 사용하는 경우
#include "SimpleHook.h"
extern "C" {
__declspec(dllexport) LRESULT CALLBACK hookProc(int code, WPARAM wParam, LPARAM lParam) {
return CallNextHookEx(0, code, wParam, lParam);
}
__declspec(dllexport) int add(int a, int b) {
return a + b;
}
}
기본 파일
#include <iostream>
#include <windows.h>
#include <tchar.h>
int main(int argc, char* argv[]) {
HINSTANCE dllHandle = LoadLibrary(_T("SimpleHook.dll"));
if (dllHandle) {
// returns the correct address
cout << "add address: " << GetProcAddress(dllHandle, "add") << endl;
// returns NULL
cout << "hookProc address: " << GetProcAddress(dllHandle, "hookProc") << endl;
}
}
astError() 의미가있는 127 오류 코드가 나타납니다.
ERROR_PROC_NOT_FOUND : 지정된 프로 시저를 찾을 수 없습니다.
이상한 점은 동일한 파일의 다른 기능이 올바르게로드된다는 것입니다. 도움을 주시면 대단히 감사하겠습니다!
이렇게하면 GetProcAddress가 얼마나 정확하게 작동합니까? –
@Ben Voigt :'__cedcl' 함수는 전혀 엉망이 없기 때문에. 제 요점은 그가 GetProcAddress를 사용하지 않아야한다는 것입니다. – Puppy
모든 상황에서 단순히'GetProcAddress' 사용을 피할 수는 없습니다. 또한 맹목적으로 호출 규칙을 변경할 수 없습니다. –