无法在动态链接库中找到过程入口点

时间:2012-06-12 22:58:04

标签: visual-c++

我正在尝试为我正在处理的游戏代理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;
}

1 个答案:

答案 0 :(得分:0)

一个大问题是在DLL_PROCESS_ATTACH发生时调用LoaLibrary。永远不要那样做!相反,请查看the Best Practices for Creating DLLs并更正此问题。您正在尝试的失败与Loader尚未完成将DLL附加到进程时调用LoadLibrary的副作用有关。