I'm trying to create a proxy dinput8.dll to allow keyboard remapping in a game, and have pieced together some instructions etc to come up with the following :
#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];
}
}
The module definition file it links against is as follows :
EXPORTS
DirectInput8Create=__E__0__ @1
DllCanUnloadNow=__E__1__ @2
DllGetClassObject=__E__2__ @3
DllRegisterServer=__E__3__ @4
DllUnregisterServer=__E__4__ @5
The project builds fine and produces the DLL, which I then place alongside originaldinput8.dll (a renamed version of C:\Windows\SysWOW64\dinput8.dll) and run the game. But it immediately crashes - a debugger run produces the following error just as the call to LoadLibrary occurs.
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).
This was previously working (after an issue where I was using the 64-bit original DLL instead of the 32-bit one) but somehow it has now stopped working and I'm not sure what the issue is.
I don't think it's an issue with it finding the DLL file - removing the DLL file or using the wrong one results in LoadLibrary failing without causing a crash, error code 193.
Any ideas?
User contributions licensed under CC BY-SA 3.0