Sign in to follow this  
Followers 0
jamesleighe

Error: ...value of ESP was not properly saved...

5 posts in this topic

(C++, Visual Studio 2010)

I get the following error when my app returns:

"Run-Time Check Failure #0 - 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."

But only if two things are true:
1) You start the app outside of the IDE and then attach to it when it breaks.
2) You call a function implemented in a lib.

This code will reproduce the error:
[code]

int __stdcall
WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, char* lpCmdLine, int nCmdShow )
{
__debugbreak();
TestFn();

return 0;
}
[/code]
(Code for lib not shown, but it would just implement 'TestFn()')

What's going on here?


edit:
Decided to show the code for the lib in case I'm doing that wrong:
test.h
[code]
bool TestFn( );
[/code]

test.cpp
[code]

bool TestFn( )
{
return true;
}
[/code]
0

Share this post


Link to post
Share on other sites
[quote]This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention[/quote]Either:
1) TestFn contains code with a buffer-overrun/etc that is corrupting the stack.
2) ^^What the error says: a function was compiled with one calling convention, but was called using another convention.

If (2), it's probably caused by the lib having been compiled using different compiler settings than your program, so that your program and the lib both have a different idea of what the default convention should be.

[edit]What happens if you use CALLBACK instead of __stdcall on winmain?
1

Share this post


Link to post
Share on other sites
[left]No dice on using [font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828]'[/color][/size][/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]CALLBACK'.[/size][/font][/color][/left]

[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]It couldn't be (1) since the fn just returns true, and (2) would be strange since I created new projects for the test and used fully default settings.[/size][/font][/color][/left]
[left](I of course switched it to compile the lib as a lib but that's all)[/left]

[left]Remember, it only happens when you run the app outside the IDE and then break in when the __debugbreak hits. If I debug it from within the IDE it runs fine![/left]

[left]EDIT:[/left]

I think I tested similar code on another PC and it did not have the issue, prompting me to reinstall windows.

Still have the error however. Could somehow be something about my PC.
0

Share this post


Link to post
Share on other sites
Just to update this, it IS something with my PC. The error will not happen on any other PC I try it on.

So it's some kind of hardware issue.
0

Share this post


Link to post
Share on other sites
Are you overclocked? All manner of weird and seemingly impossible things can happen with overclocking... http://blogs.msdn.com/b/oldnewthing/archive/2005/04/12/407562.aspx
1

Share this post


Link to post
Share on other sites
This usually happens when you're using an [b]old DLL[/b] while linking against a new lib & header that was modified.
Most likely one of the DLLs your app is using in your PC is different (newer or older) and that's why you get the error.

From what it looks like your VC Studio debug CRT DLLs are miss-matched (or your release DLLs, which are installed from a redist like [url="http://www.microsoft.com/download/en/details.aspx?id=5582"]this one[/url]). Try reinstalling Visual Studio.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0