我正在尝试为我正在开发的游戏代理 ddraw.dll(不用于作弊目的),主游戏调用了两个函数以启动它:
DirectDrawEnumerateExA
DirectDrawCreateEx
我已经将这两个都添加到了我的 C++ 项目中,并在网上进行了无数次研究,但到目前为止我一无所获,我尝试了各种教程和各种方法,例如使用 .def 文件,我似乎无法找出问题所在。
启动游戏时出现“程序入口点 DirectDrawEnumerateExA 无法位于动态链接库 DDRAW.dll 中”
这是我目前正在使用的代码库:
#include <windows.h>
#include <ddraw.h>
typedef HRESULT (WINAPI* DirectDrawEnumerateExA_td)(LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags);
typedef HRESULT (WINAPI* DirectDrawCreateEx_td)(GUID FAR *lpGuid, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkouter);
static struct
{
HMODULE hGameDLL;
char* pGameDLL;
// entry points
DirectDrawEnumerateExA_td OldDirectDrawEnumerateExA;
DirectDrawCreateEx_td OldDirectDrawCreateEx;
} g_state;
extern "C" HRESULT __declspec(dllexport) OldDirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags)
{
return g_state.OldDirectDrawEnumerateExA(lpCallback, lpContext, dwFlags);
}
extern "C" HRESULT __declspec(dllexport) WINAPI OldDirectDrawCreateEx(GUID FAR *lpGuid, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkouter)
{
return g_state.OldDirectDrawCreateEx(lpGuid, lplpDD, iid, pUnkouter);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
{
char infoBuf[MAX_PATH];
GetSystemDirectory(infoBuf, MAX_PATH);
strcat_s(infoBuf, MAX_PATH, "\\ddraw.dll");
g_state.hGameDLL = LoadLibrary(infoBuf);
g_state.pGameDLL = (char*)g_state.hGameDLL;
if(!g_state.hGameDLL)
{
MessageBox(NULL, "Unable to load ddraw.dll", "Error", MB_OK | MB_ICONEXCLAMATION);
ExitProcess(0);
}
g_state.OldDirectDrawEnumerateExA = (DirectDrawEnumerateExA_td)GetProcAddress(g_state.hGameDLL, "DirectDrawEnumerateExA");
if(!g_state.OldDirectDrawEnumerateExA)
{
MessageBox(NULL, "Unable to find entry point: DirectDrawEnumerateExA", "Error", MB_OK | MB_ICONEXCLAMATION);
ExitProcess(0);
}
g_state.OldDirectDrawCreateEx = (DirectDrawCreateEx_td)GetProcAddress(g_state.hGameDLL, "DirectDrawCreateEx");
if(!g_state.OldDirectDrawCreateEx)
{
MessageBox(NULL, "Unable to find entry point: DirectDrawCreateEX", "Error", MB_OK | MB_ICONEXCLAMATION);
}
MessageBox(NULL, "Test.", "Test Box", MB_OK | MB_ICONEXCLAMATION);
}
else if(fdwReason == DLL_PROCESS_DETACH)
{
if (g_state.hGameDLL)
{
FreeLibrary(g_state.hGameDLL);
}
}
return TRUE;
}