这里的情况是,我有一个加载xinput1_3.dll的x64位游戏。我的目标是通过将我的dll重命名为xinput1_3.dll来将我自己的代码加载到该游戏中。我知道游戏的可执行文件从xinput1_3.dll导入的函数。我试过的东西是在我的dll中使用XInput.lib和XInput.h标头导出这些函数,这样做给了我下面列出的错误:
error C2375: 'XInputGetCapabilities' : redefinition; different linkage
see declaration of 'XInputGetCapabilities'
... XInputGetState/XInputSetState
redirect.h
#include <Windows.h>
#include "Xinput.h"
#define IMPORT __declspec(dllimport)
#define EXPORT __declspec(dllexport)
EXTERN_C EXPORT DWORD WINAPI XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES *pCapabilities);
EXTERN_C EXPORT DWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE *pState);
EXTERN_C EXPORT DWORD WINAPI XInputSetState(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration);
dllmain.cpp
BOOL WINAPI DllMain( HMODULE hModule,
DWORD dwReason,
LPVOID lpReserved
)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}