我在调用Delphi编写的动态库时,无论传入什么类型的参数在C++运行时系统都会提示Run-Time Check Failure #0,全文内容如下: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。请教各位高手,这个问题如何解决?谢谢

解决方案 »

  1.   

    好像是说你的函数定义与dll中的函数定义不一致
      

  2.   

    no...
    是 調用方式不一致 stdcall or cdecl...
      

  3.   

    Delphi动态库函数为
    function dTest(str:PChar):PChar;stdcall;
    function dTest(str:PChar):PChar;     //str:pchar   str:Integer
    var
      ss : string;
    begin
      ss := str;
      ShowMessage(ss);
      Result := PChar('This is a test!');
    end;
    通过showmessage函数显示传入函数的字符串,没有问题,但是系统执行后弹出错误信息对话框,提示上述错误。
    C++中的程序为
    typedef LPCSTR(_cdecl *Connect)(LPCSTR s);
    HINSTANCE hinstDLL=NULL; 
    hinstDLL=LoadLibrary("../dllTest.dll");
    if (hinstDLL)
    {
    Connect Proc;
    char p[100] ;
        CString csTemp;
    p[99] = '\0';
    Proc = (Connect)GetProcAddress (hinstDLL,"dTest");
    LPCSTR iValue;//int 
    CString str;
    str.Format("This is a test");
    LPCSTR sss = "abcxsw";
    iValue = Proc(sss);//m_i  str
            strncpy(p,iValue,100);
    csTemp.Format(p);
    FreeLibrary(hinstDLL); AfxMessageBox(p);
    }
    else
    {
    AfxMessageBox("没找到dll");
    }
    帮帮忙,谢谢,不知道如何解决。
      

  4.   

    楼主你的c++代码明显是cdecl调用的,当然会挂掉。
      

  5.   

    //typedef LPCSTR(_cdecl *Connect)(LPCSTR s);
    typedef LPCSTR(_stdcall *Connect)(LPCSTR s);
      

  6.   

    Delphi动态库函数为
    function dTest(str:PChar):PChar;cdecl;type PTestFunc = function(str:PChar):PChar; cdecl;
      

  7.   

    硕大的_cdecl在这里…… 唉……