我正在尝试创建一个代理dinput8.dll以允许在游戏中重新键入键盘,并拼凑了一些指令等以提出以下内容:
#include <windows.h>
#include <strsafe.h>
#pragma pack(1)
HINSTANCE hLThis = 0;
HINSTANCE hL = 0;
FARPROC p[5] = {0};
BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID) {
if (reason == DLL_PROCESS_ATTACH) {
hLThis = hInst;
hL = LoadLibrary("originaldinput8.dll");
if (!hL) return false;
p[0] = GetProcAddress(hL,"DllCanUnloadNow");
p[1] = GetProcAddress(hL,"DllGetClassObject");
p[2] = GetProcAddress(hL,"DllRegisterServer");
p[3] = GetProcAddress(hL,"DllUnregisterServer");
p[4] = GetProcAddress(hL,"DirectInput8Create");
} else if (reason == DLL_PROCESS_DETACH) {
FreeLibrary(hL);
}
return 1;
}
extern "C" __declspec(naked) void __stdcall __E__0__()
{
__asm
{
jmp p[4];
}
}
// DllCanUnloadNow
extern "C" __declspec(naked) void __stdcall __E__1__()
{
__asm
{
jmp p[0];
}
}
// DllGetClassObject
extern "C" __declspec(naked) void __stdcall __E__2__()
{
__asm
{
jmp p[1];
}
}
// DllRegisterServer
extern "C" __declspec(naked) void __stdcall __E__3__()
{
__asm
{
jmp p[2];
}
}
// DllUnregisterServer
extern "C" __declspec(naked) void __stdcall __E__4__()
{
__asm
{
jmp p[3];
}
}
它链接的模块定义文件如下:
EXPORTS
DirectInput8Create=__E__0__ @1
DllCanUnloadNow=__E__1__ @2
DllGetClassObject=__E__2__ @3
DllRegisterServer=__E__3__ @4
DllUnregisterServer=__E__4__ @5
项目构建正常并生成DLL,然后我将其放在originaldinput8.dll(C:\ Windows \ SysWOW64 \ dinput8.dll的重命名版本)旁边并运行游戏。但它会立即崩溃 - 调试器运行会产生以下错误,就像调用LoadLibrary一样。
First-chance exception at 0x75ed75f8 in th06e.exe: 0xC0000005: Access violation reading location 0x00000250.
*** An Access Violation occurred in "C:\Users\Username\Documents\Visual Studio 2010\Projects\dinput8\Debug\th06e.exe" :
The instruction at 00000000775A1221 tried to read from an invalid address, 0000000000000250
*** enter .exr 000000000008E030 for the exception record
*** enter .cxr 000000000008DB40 for the context
*** then kb to get the faulting stack
Unhandled exception at 0x75ed75f8 in th06e.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
The program '[5704] th06e.exe: Native' has exited with code -1073740771 (0xc000041d).
这是以前工作的(在我使用64位原始DLL而不是32位的问题之后)但不知怎的,它现在已停止工作,我不确定是什么问题。
我不认为这是找到DLL文件的问题 - 删除DLL文件或使用错误的文件导致LoadLibrary失败而不会导致崩溃,错误代码193。
有什么想法吗?