嗯,我有一些問題,我不明白的錯誤。DLL GetProcAddress問題 - 另一個運行時檢查失敗
這是兩個相關文件:
內DLLExporter:
#ifdef LOGGER_EXPORTS
#define LOGGER_API __declspec(dllexport) __stdcall
#else
#define LOGGER_API __declspec(dllimport) __stdcall
#endif
typedef long (CALLBACK *LPFNTIMER)(void);
// Exported Functions
bool LOGGER_API Initialize(std::string filename, bool ShowConsole = true);
bool LOGGER_API Release(void);
bool LOGGER_API SetTimer(LPFNTIMER);
bool LOGGER_API Initialize(std::string filename, bool ShowConsole)
{
[...]
}
bool LOGGER_API Release()
{
[...]
}
bool LOGGER_API SetTimer(LPFNTIMER fn)
{
[...]
}
內DLLExporter.def
LIBRARY DLLExporter.dll
EXPORTS
Initialize
Release
SetTimer
內DLLImporter:
typedef long (__stdcall *LPFNTIMER)(void);
typedef bool (__stdcall *LPFNINITIALIZER)(string, bool);
typedef bool (__stdcall *LPFNTIMERSETUP)(LPFNTIMER);
typedef bool (__stdcall *LPFNRELEASER)(void);
[...]
long __stdcall TimerFunc()
{
return 0;
}
[...]
if (g_DLLExporter == NULL)
return false;
LogInit = (LPFNINITIALIZER)GetProcAddress(g_DLLExporter, "Initialize");
LogRelease = (LPFNRELEASER)GetProcAddress(g_DLLExporter, "Release");
LogTimer = (LPFNTIMERSETUP)GetProcAddress(g_DLLExporter, "SetTimer");
if (LogInit == NULL || LogRelease == NULL || LogTimer == NULL)
return false;
if (!LogInit("test.log", true))
return false;
if (!LogRelease())
return false;
if (!LogTimer(TimerFunc))
return false;
此代碼一直運行到LogTimer調用失敗,並帶有運行時檢查失敗#0消息。
運行時檢查失敗#0 - 值ESP的 未正確保存跨 函數調用。這通常是調用聲明 與用 不同調用約定聲明的 函數指針一個調用約定函數的 結果。
我已經注意到其他地方報道的__stdcall的問題,但你可以在上面看到我有,包括,我甚至被迫__stdcall調用項目屬性公約(2010 MSVS)。任何想法,爲什麼我只會在計時器函數上獲取錯誤,而不是在init或release函數上?
這應該是這樣嗎? – Mehrdad 2011-04-04 00:56:37
這是一個win32應用程序。 DLLExporter創建DLLExporter.dll DLLImporter創建DLLImporter.exe其中進口DLLExporter.dll在運行時 – 2011-04-04 01:17:51