Euler
Euler

Reputation: 652

The value of ESP was not properly saved across a function call

I am working on a Visual studio project Project A (which generates a static lib on compilation)

has a class

using namespace mynamespace;
class projectAclass
{
  virtual int  funct1()=0;  //Pure virtual function
  virtual int funct2()=0;  //Pure virtual function
  virtual int funct3()=0;  //Pure virtual function
};

Project B(which generates a DLL on compilation)

#define projectBclass_DLL __declspec( dllexport )
class projectBclass_DLL projectBclass: public mynamespace::projectAclass
{
  //Definitions of the 3 pure virtual functions are here
  int funct1() 
  {
    //definition go here
  }
  //similarly for funct2 and funct3

  int funct4()
 { //Definition goes here    }
  int funct5()
 { //Definition goes here    }
  int funct6()
 { //Definition goes here    }
};

Now from the main function created in some other project I have created an object of class projectAclass and trying to call function funct1 but i don't know some other function is getting called that are defined in projectBclass (let say funct4) when i am trying to debug the solution and after returning from funct4 I am getting this error

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.

Thanks in advance

Upvotes: 2

Views: 12120

Answers (2)

Thorsten
Thorsten

Reputation: 213

Make sure that the static library that is linked to your dll, the dll and (because you are creating a C++ DLL) your application have the same build configuration (DEBUG/RELEASE). Check the preprocessor flags in your project. Wrong preprocessor flags can lead to different virtual function pointer tables and therefore it can easily happen that the wrong function is called.

Upvotes: 2

doctorlove
doctorlove

Reputation: 19272

Sometimes you have the calling conventions wrong. Sometimes a rebuild of everything will sort it.

Upvotes: 2

Related Questions