2011-10-12 113 views
0

我正在使用函數指針和LoadLibrary。以下是我的代碼。當我在_EvtSubscribe調用後添加EvtExportLog時,它開始破壞_EvtSubscribe值,如果我之前在以下代碼中添加它,現在一切正常,現在當我添加另一個函數指針時,我面臨同樣的問題,任何人都知道這裏可能是什麼問題。函數指針和DLL加載順序

 HMODULE module = LoadLibrary(L"wevtapi.dll"); 
    _EvtExportLog    = (BOOL (WINAPI *)(EVT_HANDLE ,LPCWSTR ,LPCWSTR ,LPCWSTR ,DWORD))GetProcAddress(module, "EvtExportLog"); 
    _EvtClearLog    = (BOOL (WINAPI *)(EVT_HANDLE ,LPCWSTR,LPCWSTR,DWORD))GetProcAddress(module, "EvtClearLog"); 
    _EvtOpenLog    = (EVT_HANDLE (WINAPI *)(EVT_HANDLE ,LPCWSTR ,DWORD))GetProcAddress(module, "EvtOpenLog"); 
    _EvtGetLogInfo   = (BOOL (WINAPI *)(EVT_HANDLE, EVT_LOG_PROPERTY_ID, DWORD, PEVT_VARIANT ,PDWORD))GetProcAddress(module, "EvtGetLogInfo"); 
    _EvtQuery     = (EVT_HANDLE (WINAPI *)(EVT_HANDLE,LPCWSTR ,LPCWSTR ,DWORD))GetProcAddress(module, "EvtQuery"); 
    _EvtNext     = (BOOL (WINAPI *)(EVT_HANDLE ,DWORD,EVT_HANDLE*,DWORD,DWORD,PDWORD))GetProcAddress(module, "EvtNext"); 
    _EvtClose     = (BOOL (WINAPI *)(EVT_HANDLE))GetProcAddress(module, "EvtClose"); 
    _EvtCreateRenderContext = (EVT_HANDLE (WINAPI *)(DWORD, LPCWSTR *, DWORD))GetProcAddress(module, "EvtCreateRenderContext"); 
    _EvtFormatMessage   = (BOOL (WINAPI *)(EVT_HANDLE, EVT_HANDLE, DWORD, DWORD, PEVT_VARIANT, DWORD, DWORD, LPWSTR, PDWORD))GetProcAddress(module, "EvtFormatMessage"); 
    _EvtOpenPublisherMetadata = (EVT_HANDLE (WINAPI *)(EVT_HANDLE, LPCWSTR, LPCWSTR, LCID, DWORD))GetProcAddress(module, "EvtOpenPublisherMetadata"); 
    _EvtRender    = (BOOL (WINAPI *)(EVT_HANDLE, EVT_HANDLE, DWORD, DWORD, PVOID, PDWORD, PDWORD))GetProcAddress(module, "EvtRender"); 
    _EvtSubscribe    = (EVT_HANDLE (WINAPI *)(EVT_HANDLE, HANDLE, LPCWSTR, LPCWSTR, EVT_HANDLE, PVOID, EVT_SUBSCRIBE_CALLBACK, DWORD))GetProcAddress(module, "EvtSubscribe"); 
+0

該問題可能與訂單無關。如果問題與此代碼有關,那麼很可能您的功能簽名是錯誤的。 – tenfour

回答

3

這有什麼好做DLL的加載順序,你搗毀堆中的其他位置,它只是碰巧_EvtSubscribe是受害者,這取決於你如何訂購堆棧上的對象上。垃圾堆棧最簡單的方法是,如果您使用錯誤的簽名調用某個函數,可能是通過手工抄錄而不是僅使用靜態鏈接和頭文件。