Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ LoadLibrary导致访问冲突_C++_Windows_Directinput - Fatal编程技术网

C++ LoadLibrary导致访问冲突

C++ LoadLibrary导致访问冲突,c++,windows,directinput,C++,Windows,Directinput,我正在尝试创建一个代理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) {

我正在尝试创建一个代理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];
        }
    }
该项目构建得很好,生成了DLL,然后我将其放在OriginalInput8.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文件有什么问题-删除DLL文件或使用错误的DLL文件会导致LoadLibrary失败而不会导致崩溃,错误代码193


有什么想法吗?

调试器打印下一步操作的指令。遵循它们并调试您得到的结果。MSDN明确指出,不应该从
DllMain
调用
LoadLibrary
,但我仍然不知道为什么在这个特定场景中它会中断。@unkulunkulu哦,我没有意识到。就像我说的,它以前是有效的,但我会努力改变它,然后看看它是否有效。听雷蒙德说。没有人比他更了解这件事了
jmp[4]
没有做你希望它做的事。它不是作为C索引表达式计算的,偏移量4是汇编中的字节偏移量。因此,实际上是在32位模式下跳到p[1]。在64位模式下,您可以跳转到wazoo,如0x250。
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).