Different function is getting called

Hi,
Please Help me! I encounter a typical 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.

After I got this Error I turned off /GZ option in the settings and this problem got solved, but in the code when a call is made for one function (say draw())another function (nonKeyEventProcessing()) is getting called.

Any help you can lend me will be greatly appreciated.

Jamis's picture

I was getting that same error not two days ago. I had no idea what was causing this error. I am working on a project that interfaces with another library. Are you interfacing with an external lib? If so, you might have a conflict with one of your header files and your current library version. If this is the case, I would suggest updating your library and/or header files. Hope that helps!

Ramya's picture

Hope this info will help u>>>>>>>>>>>>>>>>

SYMPTOMS
When you run the debug build of your application with the /RTCs compiler option enabled, you may receive the following exception error message:
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.
You receive this error message when the following conditions are true: • You call a function that does not use the __cdecl modifier.
• The function contains parameters that are larger than 64 kilobytes (KB).
• You compile your application in the Debug mode and with the /RTCs compiler option enabled.

Back to the top

CAUSE
When you pass a parameter that is 64 KB or larger to a function that does not use the __cdecl modifier, the compiler generates incorrect code. When the function that is called tries to return control to the calling function, the compiler triggers the error that is mentioned in the "Symptoms" section. The compiler generates a 16-bit immediate return (RET) that has an operand that is limited to 64 KB. If the parameters that are passed to the function are larger than 64 KB, the stack becomes corrupted when the function returns.
Back to the top

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Back to the top

MORE INFORMATION
Steps to reproduce the behavior
1. Start Visual Studio .NET.
2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
3. Under Project Types, click Visual C++ Projects, and then click Win32 Project under Templates.
4. In the Name box, type MyProject, and then click OK. The Win32 Application Wizard - MyProject dialog box appears.
5. On the Welcome to the Win32 Application Wizard page, click Application Settings. The Application Settings page appears.
6. Click Console application, and then click Finish.
7. In Solution Explorer, right-click MyProject.cpp, and then click Open.
8. Locate the following code in the MyProject.cpp file:#include "stdafx.h"

9. Add the following code after the code that you located in step 8:struct MyStruct
{
unsigned char MyData[65535];
};

void __stdcall MyFunc(MyStruct m_MyStruct)
{
m_MyStruct.MyData[0] = 'G';
return;
}

10. Replace the existing code in the _tmain procedure with the following code: MyStruct m_Temp;
MyFunc(m_Temp);
return 0;

11. In Solution Explorer, right-click MyProject, and then click Properties. The MyProject Property Pages dialog box appears.
12. In the left pane of the MyProject Property Pages dialog box, click Configuration Properties.
13. Under Configuration Properties, click C/C++, and then click Code Generation.
14. Set the Basic Runtime Checks property to Stack Frames (/RTCs).
15. Click Configuration Manager. The Configuration Manager dialog box appears.
16. In the Active Solution Configuration list, click Debug, and then click Close.
17. In the MyProject Property Pages dialog box, click OK.
18. On the File menu, click Save All to save all the files.
19. On the Build menu, click Build Solution to build the application.
20. On the Debug menu, click Start to run the application.

Back to the top

REFERENCES
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
__cdecl
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/...
/RTC (Run-time error checks)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vcce...