Jeffrey Magder | reply 2003-07-08 21:53
I was having the same problem, but I just FIXED it. I was getting the same error from the following code:
HMODULE hPowerFunctions = LoadLibrary("Powrprof.dll");
typedef bool (*tSetSuspendStateSig)(BOOL, BOOL, BOOL);
tSetSuspendState SetSuspendState = (tSuspendStateSig)GetProcAddress(hPowerfunctions, "SetSuspendState");
result = SetSuspendState(false, false, false); <---- This line was where the error popped up.
After some investigation, I changed one of the lines to:
typedef bool (WINAPI*tSetSuspendStateSig)(BOOL, BOOL, BOOL);
which solved the problem. If you take a look in the header file where SetSuspendState is found (powrprof.h, part of the SDK), you will see the function prototype is defined as:
BOOLEAN WINAPI SetSuspendState(BOOLEAN, BOOLEAN, BOOLEAN);
So you guys are having a similar problem. When you are calling a given function from a .dll, its signature is probably off. (In my case it was the missing WINAPI keyword).
Hope that helps any future people! :-)
Cheers.
只所以會產生這種原因,這位老外沒有深入解釋。
產生這個問題是由於調用第三方DLL引起的。
如下DLL導出函數注意那個 __stdcall)
extern "C" __declspec(dllexport) __stdcall int myAdd(int,int);
extern "C" __declspec(dllexport) __stdcall AnsiString aboutMe(void);
__stdcall的意識是
被這些修飾關鍵字修飾的函數,其參數都是從右向左通過堆棧傳遞的(__fastcall 的前面部分由ecx,edx傳), 函數調用在返回前要清理堆棧,但由調用者還是被調用者清理不一定。如果在加載這個DLL並且引入函數時使用如下形式 typedef int(*lpAdd)(int a,int b);HINSTANCE HmyDLL=LoadLibrary(_T("myDLL.dll")); lpAdd tAdd =(int (*)(int,int))P;
本文出自 “風清揚song” 博客,請務必保留此出處http://2309998.blog.51cto.com/2299998/1273090