Jeffrey Magder | reply
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 investors, I changed one of the lines:
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:
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.
Dheeraj | reply
This is why this problem occurs. The foreigner did not explain it in depth.
This problem is caused by calling a third-party DLL.
Note the _ stdcall for the DLL export function below)
Extern "C" _ declspec (dllexport) _ stdcall int myAdd (int, int );
Extern "C" _ declspec (dllexport) _ stdcall AnsiString aboutMe (void );
_ Stdcall awareness is
The parameters of a function modified by these modifier keywords are passed from right to left through the stack (the first part of _ fastcall is passed by ecx and edx ), the stack should be cleared before function calls are returned, but it is not necessarily cleared by the caller. If typedef int (* lpAdd) (int a, int B); HINSTANCE HmyDLL = LoadLibrary (_ T ("myDLL. dll "); lpAdd tAdd = (int (*) (int, int) P;
Int n = tAdd (); // This step will result in an error !!!! Only the WINAPI mentioned above can be used. The following format is typedef int (WINAPI * lpAdd) (int a, int B); HINSTANCE HmyDLL = LoadLibrary (_ T ("myDLL. dll "); lpAdd tAdd = (int (WINAPI *) (int, int) P; int n = tAdd (10, 20); // No error will occur this time !!! Because # define WINAPI _ stdcall, if _ stdcall is used in the DLL export function, the _ stdcall statement must also be used before the function declaration in the call to import DLL functions. If the export DLL function does not use _ stdcall for export, the import DLL function does not need to use _ stdcall. Otherwise, the above error is reported.
This article is from the "Feng qing yang song" blog, please be sure to keep this source http://2309998.blog.51cto.com/2299998/1273090