DLL 调用错误 -The value of ESP was not properly saved across a function call.

http://blog.csdn.net/HappySong/archive/2005/04/07/339707.aspx

在调用DLL中的函数有时候会出现如下对话框的错误:

Microsoft Visual C++ Debug Library:

Debug Error:
Program: ...
Module:
File: i386/chkesp.c
Line: 42

The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

(Press Retry to Debug the Application)

其解决方法之一是:

在函数调用前加入 WINAPI ,详细见下列摘录文章。

From http://www.opencascade.org/org/forum/thread_2812/

Help! Calling Convention Error!
fhchina | reply 2002-04-27 14:43
Please Help me! I encounter the such `splendid' error at runtime:

Microsoft Visual C++ Debug Library:

Debug Error:
Program: ...
Module:
File: i386/chkesp.c
Line: 42

The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

(Press Retry
fhchina | reply 2002-04-27 14:49
Sorry, misclick the mouse, the following is the correct message.

Please Help me! I encounter the such `splendid' error at runtime:

Microsoft Visual C++ Debug Library:

Debug Error:
Program: ...
Module:
File: i386/chkesp.c
Line: 42

The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

(Press Retry to Debug the Application)

Then Press Retry to debug it, each time I found my program abort at the following code:

/////////////////////////
// aLine is a pointer of AIS_Line.
Handle(Geom_Point) hStart, hEnd;
aLine->Points(hStart, hEnd);

TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge(hStart->Pnt(), hEnd->Pnt());

Each time the call stack will show the program abort on the final line. Why?
I think I shouldn't consider any calling convention as an Application developer. And this segment is runing very well before I introduce OCAF into my application. And I have checked all the compiler options, it seems no problem. Please help me!
Lugi.C | reply 2002-04-28 02:09
Maybe you need rebuild all your files of the projects.
fhchina | reply 2002-04-28 06:52
Thanks for your response. I have solved the problem last night. But before report this error I have rebuild all of my files include both Debug & Release version. The error still exists, even I turned off /GZ option. And I have found some similar posts on the Internet by Google, but there is no statisfactory solution or explanation. As far as my experience for this error, it usually a logic error of code. And I guess this kind of logic error cause this ESP register check error.( The concrete reason is still unknown), but it must not be the calling convention mismatch.
manoj vithanage | reply 2002-11-06 11:37
thank you very much. u saved me from a lot of trouble. thanx again
Parthasarathy | reply 2003-07-05 19:20
Great!! , i also have the same probs, but u guys are saved me...
thanks lot.
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.

Dheeraj | reply 2003-08-21 23:25
Hi,

I was alos getting the same kind of error. I have tried what way u suggested in a function pointer. I have added WINAPI to a function pointer and my program worked.

Thanks for the such information which helped me.
Dheeraj | reply 2003-08-21 23:25
Hi,

I was alos getting the same kind of error. I have tried what way u suggested in a function pointer. I have added WINAPI to a function pointer and my program worked.

Thanks for the such information which helped me.


Hope to get more information of such nature.

Cheers
Jagadish Kumar | reply 2003-12-16 02:17
Hi,

I was having the same problem. It got fixed with your solution. Thanx a lot. It really saved a lot of time.

Cheers,
Jagadish
Christian Posta | reply 2004-11-23 01:27
Thanks a lot, you really saved me a lot of frustration by adding the WINAPI signature word!!
Pasi | reply 2004-12-16 12:49
This really helped me a lot! Thank you very much! The word I was missing was CALLBACK. :)
Dilshan Jesook | reply 2005-01-03 15:47
I was having this same problem with that stupid runtime error allways poping up, and solved it by typing in the WINAPI keyword... problem solved. Thanks to such forum.
John | reply 2005-03-09 14:55
Thak you very much, I had exactly the same error.

Thanks.
Ben | reply 2004-04-16 11:14
I have the same problem when I call a function in an ATL Dll from VB.
There is no more error message during runtime when removing /GZ option, however VB generate an exception when I close it...
K | reply 2003-01-21 16:46
I just got that message last night- what did you do to fix it? I'm hoping to not have to reformat
KMP | reply 2003-03-11 21:26
I'm facing the same problem. and as said, its pointing to the end of a func call. In this function, I have called a funtion pointer that stores the address returned by the API call GetProcAddress(). which is inturn usedfor thunking from 32 bits to 16 bits.

Other than removing /GZ, is there any other
Prashant Deshmukh | reply 2003-04-01 08:40
I came across this Debug error message when I was parsing XML using Xerces ->Dom parser
It seems to be logical error Since
The code worked when I tried
Typcasting direct (DOMText *) DOMNode *
But fails if I am trying to access a method GetWholeText() by typcasting like
(DOMText *) (DOMCharachter)DOMNode *


Do any body have solution or reason why this is happening ????
KMP | reply 2003-03-11 21:26
I'm facing the same problem. and as said, its pointing to the end of a func call. In this function, I have called a funtion pointer that stores the address returned by the API call GetProcAddress(). which is inturn usedfor thunking from 32 bits to 16 bits.

Other than removing /GZ, is there any other way out.

Karim Sharif | reply 2003-12-09 22:49
In my case it turned out to be an invalid memory
initlization to zero, which wiped out whatever was
on stack. All these happend in the DLL which was
being call from my C++ program.
Lucia | reply 2003-10-28 12:04
hello,
I have the same error. I found it when i added a bitmap in my flexgrid. This is my code:

......
CPictureHolder pic;
pic.CreateBitmap(IDB_BITMAP);
m_grid.SetRefCellPicture(pic.GetPictureDispatch);
.....

I,ve seen that the problem is the following: when i call Createbitmap or any function of CpictureHolder class, my program jump to an incorrect address in MFCO42D.dll, BUT I DON碩 KNOW WHY, ANYONE CAN HELP ME?? THANKS
Stephanie ENGRAND | reply 2004-03-25 23:51
I encounter the same error :
It was because I forgot to put :

using std::basic_string;

I hope this help you

(sorry for my English but I'm French)
K関in Kadri | reply 2004-11-13 10:04

email me

你可能感兴趣的:(DLL 调用错误 -The value of ESP was not properly saved across a function call.)