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

来源:互联网 发布:淘宝客哪里可以关闭 编辑:程序博客网 时间:2024/05/01 13:23

在调用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 | reply2002-04-27 14:43Please 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 Retryfhchina | reply2002-04-27 14:49Sorry, 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 | reply2002-04-28 02:09Maybe you need rebuild all your files of the projects.fhchina | reply2002-04-28 06:52Thanks 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 | reply2002-11-06 11:37thank you very much. u saved me from a lot of trouble. thanx againParthasarathy | reply2003-07-05 19:20Great!! , i also have the same probs, but u guys are saved me...
thanks lot.
Jeffrey Magder | reply2003-07-08 21:53I 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 | reply2003-08-21 23:25Hi,

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 | reply2003-08-21 23:25Hi,

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.

CheersJagadish Kumar | reply2003-12-16 02:17Hi,

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

Cheers,
JagadishChristian Posta | reply2004-11-23 01:27Thanks a lot, you really saved me a lot of frustration by adding the WINAPI signature word!!Pasi | reply2004-12-16 12:49This really helped me a lot! Thank you very much! The word I was missing was CALLBACK. :)Dilshan Jesook | reply2005-01-03 15:47I 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 | reply2005-03-09 14:55Thak you very much, I had exactly the same error.

Thanks.Ben | reply2004-04-16 11:14I 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 | reply2003-01-21 16:46I just got that message last night- what did you do to fix it? I'm hoping to not have to reformatKMP | reply2003-03-11 21:26I'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 | reply2003-04-01 08:40I 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 | reply2003-03-11 21:26I'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 | reply2003-12-09 22:49In 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 | reply2003-10-28 12:04hello,
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 | reply2004-03-25 23:51I 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 | reply2004-11-13 10:04email me

原创粉丝点击