我将别人以前写的一个delphi转换为dll,给vc调用。
导出函数定义如下:function CreateDoubleLayerPDF (sPath:PChar):integer; stdcall;
  begin
  Application.Initialize;
  Application.CreateForm(Tfrm_main, frm_main);
  frm_main.SetPath(sPath);
  Application.Run;
  result := 0;
  end;
exports CreateDoubleLayerPDF;
在Tfrm_main中的退出过程中,直接调用close;
但是vc调用后,直接退出,会出现错误,提示如下:the value of ESP was not properly saved across a fnction call.This is usually a result of callin a function declared with one calling convention with a function pointer declared with a different calling convention。VC中调用的函数定义如下:typedef int(*CreatePDF)(char*);急啊!!大家帮帮忙吧!

解决方案 »

  1.   

    调用约定不对,你在VC中也指定了stdcall调用方式吗?
      

  2.   

    typedef int(_stdcalk *CreatePDF)(char*); 
      

  3.   

    楼上两位正解 调用需要指定方式 
    VC与delphi的dll想互调用(转载)
    VC中DLL声名格式: Extern “C” void __declspec(dllexport) __stdcall ShowMess(HWND hwnd, char* mess);输出格式为:_ShowMess@8,“8”为函数参数字节数为了避免名称分裂,可采用以下方法解决:1.声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。2.在VC工程中添加def文件,如:LIBRARYEXPORTSShowMess @1则DLL中输出函数名称不分裂。
    Delphi中调用格式: Procedure ShowMess (h:HWND; mess:PChar); Stdcall;{Cdecl;} external LibName;如无Stdcall或Cdecl声名,Delphi默认Register(FastCall)调用格式。
    注意Delphi与VC的对齐格式不同,在VC中定义结构时要用以下格式: #pragma pack(4)//结构定义#pragma pack()
    常用工具: TDump.exe-Delphi 4 和 C++ Builder 3 提供Impdef.exe 和 Implib.exe - C++ Builder 3提供DumpBin.exe-VC5.0提供Lib.exe-VC5.0提供
    VC调用Delphi的DLLDelphi中的声名格式: Function ShowDialog( hMainWnd:THandle; Msg:PChar ):integer; stdcall;输出到Dll文件中时,名称不分裂。
    VC中的调用格式: extern "C" __declspec(dllimport) int __stdcall ShowDialog( HWND hwnd,char* Msg );.如带有__stdcall,则要求Lib文件中对应函数名称分裂,可有以下步骤生成Lib文件:.用Impdef.exe生成def文件,格式为:Impdef def文件名 dll文件名.手工调制def文件参数,如ShowDialog改为ShowDialog@8.用Lib.exe生成lib文件,格式为:Lib /def:def文件名.如声名中无__stdcall,默认调用格式仍为stdcall,但不要求名称分裂,用以下批处理文件MkLib.bat可生成Lib文件:@echo offif %1.==. goto errorimpdef %1.def %1.dlllib /def:%1.defgoto end:errorecho Usage: MkLib DllNameecho Note: Don t add extension ".dll" to parameter "DllName":end