2012-06-12 70 views
0

我正在嘗試爲我正在工作的遊戲(不是作弊目的)代理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; 
} 
+0

那麼,該消息看起來是適當的。你確實*沒有*實現這些功能。 –

回答

0

當DLL_PROCESS_ATTACH發生時,一個大問題是對LoaLibrary的調用。永遠不要這樣做!相反,看看the Best Practices for Creating DLLs並更正此問題。您正在嘗試的失敗與Loader尚未完成將DLL附加到進程時調用LoadLibrary的副作用有關。

+0

啊,我以前在第一個__declspec函數裏有它,但是我遇到了同樣的問題 –

+0

當然,多虧了Hans!您聲明但忘記執行您覆蓋的功能。 – mox

+0

啊,謝謝,你能指出我的正確方向嗎?我對C++相當陌生 –

相關問題