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

This topic is 2521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

(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:
 int __stdcall WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, char* lpCmdLine, int nCmdShow ) { __debugbreak(); TestFn(); return 0; } 
(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
 bool TestFn( ); 

test.cpp
 bool TestFn( ) { return true; } 

##### Share on other sites
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.

What happens if you use CALLBACK instead of __stdcall on winmain?

##### Share on other sites

No dice on using [font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828]'[/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

### 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.[/font](I of course switched it to compile the lib as a lib but that's all)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!EDIT: 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.

##### 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.

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

##### Share on other sites
This usually happens when you're using an old DLL 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 this one). Try reinstalling Visual Studio.

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×