For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Help! Calling Convention Error!

fhchina's picture
Forums: 

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's picture

Maybe you need rebuild all your files of the projects.

fhchina's picture

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 satisfactory 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's picture

thank you very much. u saved me from a lot of trouble. thanx again

Parthasarathy's picture

Great!! , i also have the same probs, but u guys are saved me...
thanks lot.

Jeffrey Magder's picture

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);

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's picture

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's picture

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's picture

Thanks a lot, you really saved me a lot of frustration by adding the WINAPI signature word!!

Pasi's picture

This really helped me a lot! Thank you very much! The word I was missing was CALLBACK. :)

Dilshan Jesook's picture

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's picture

Thak you very much, I had exactly the same error.

Thanks.

Daniel Paredes's picture

Thank you very much. I was having the same error and it was solved when I added the WINAPI word.

Regards

Apophys's picture

Thanks a lot guys! The answer really helped!

You saved me from a lot of trouble!

Jimmy Laenen's picture

Jeffrey Magder YOU ARE THE MAN!!

Thanks for your post it helped me out big time

Ben's picture

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's picture

I just got that message last night- what did you do to fix it? I'm hoping to not have to reformat

KMP's picture

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.

Prashant Deshmukh's picture

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 ????

Karim Sharif's picture

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's picture

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´T KNOW WHY, ANYONE CAN HELP ME?? THANKS

Stephanie ENGRAND's picture

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évin Kadri's picture

email me

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.