Georges5 0 Newbie Poster

Hello All,

I have a Borland C++ generated DLL, which Iam using with VC++, I managed to generate the .Lib file compatible with VC++.
Now my programs compiles and run, after that I get run-time error as follows:

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.

while Debugging my program here is the situation:
- The program crashes on the statement after where I call the function exported by the DLL.
- The value returned by the function is correct.

Here is what I did to convert the .Lib file of the DLL from Borland C++ to VC++.

I have generated a .hpp file from the pascal code for 2 functions to be exported by my DLL.

the files content are as follows:

fisprob.hpp

// Borland C++ Builder
// Copyright (c) 1995, 2002 by Borland Software Corporation
// All rights reserved

// (DO NOT EDIT: machine generated header) 'fisprob.pas' rev: 6.00

#ifndef fisprobHPP
#define fisprobHPP

namespace Fisprob
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern PACKAGE float __fastcall FISPRO(float VARI, int NUME, int DENO);

}	/* namespace Fisprob */
using namespace Fisprob;

chiprodouble.hpp
// Borland C++ Builder
// Copyright (c) 1995, 2002 by Borland Software Corporation
// All rights reserved

// (DO NOT EDIT: machine generated header) 'chiprodouble.pas' rev: 6.00

#ifndef chiprodoubleHPP
#define chiprodoubleHPP

//-- user supplied -----------------------------------------------------------

namespace Chiprodouble
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern PACKAGE void __fastcall CHIPROB(double X, int DF, double &PRO);

}	/* namespace Chiprodouble */
using namespace Chiprodouble;

then I created a file named: chaidinterface.h as follows:

#ifndef ChaidInterfaceH
#define ChaidInterfaceH
//--------------------------------------------------------------------------

#ifdef __cplusplus /* if in a C++ program */
  extern "C"
#endif

void __declspec(dllimport) WINAPI chiprobLib(double, int, double &);
float __declspec(dllimport) WINAPI fisprobLib(float, int, int);

#endif

after building my DLL, I issued the command:
- impdef chaidlib.def chaidlib.dll to generate the DEF file.
my def file looks like this:

LIBRARY CHAIDLIB.DLL

EXPORTS
@@Chaidinterface@Finalize @10 ; __linkproc__ Chaidinterface::Finalize
@@Chaidinterface@Initialize @9 ; __linkproc__ Chaidinterface::Initialize
@Chiprodouble@CHIPROB$qqrdird @1 ; __fastcall Chiprodouble::CHIPROB(double, int, double&)
@Chiprodouble@Finalization$qqrv @2 ; __fastcall Chiprodouble::Finalization()
@Chiprodouble@initialization$qqrv @3 ; __fastcall Chiprodouble::initialization()
@Fisprob@FISPRO$qqrfii @4 ; __fastcall Fisprob::FISPRO(float, int, int)
@Fisprob@Finalization$qqrv @5 ; __fastcall Fisprob::Finalization()
@Fisprob@initialization$qqrv @6 ; __fastcall Fisprob::initialization()
@fisprobLib$qfii @8 ; fisprobLib(float, int, int)
___CPPdebugHook @11 ; ___CPPdebugHook
_chiprobLib @7 ; _chiprobLib

I channged the last 3 lines as follows:

fisprobLib @8 ; fisprobLib(float, int, int)
___CPPdebugHook @11 ; ___CPPdebugHook
chiprobLib @7 ; _chiprobLib

then issue the command: lib /DEF:chaidlib2.def /out:chaidlib.lib

to generate the chaidlib.lib to be used in VC++.

Any Suggestions....

Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.