DLL call error-The value of ESP was not properly saved stored ss a f

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.