下面的代码是调用c写的dll,但是怎么竟然编译出错,哪位大侠出手相助?

解决方案 »

  1.   

    //不好意思
    unit dlltest;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type  TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        Function add(var1,var2:integer):integer;stdcall;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
      Const DllName='d:\work\develop\dlltest_delphi\add.dll';
      function add;external DllName;        {$R *.DFM}
    procedure TForm1.Button1Click(Sender: TObject);
    var
     res:integer;
    begin
     res:= add(1,2);
    end;end.
      

  2.   

    函数必须有返回值
    eg :
    function add :integer;external DllName;
      

  3.   

    改完之后,上面那各代码又出错了:
    type  TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        Function add(var1,var2:integer):integer;stdcall;//就是这句编译出错,奇怪!
      private编译错误为:
    66. Unsatisfied forward or external declaration: '<Procedurename>'但是我只是声明一下又为什么去外部找?
      

  4.   

    Function add(var1,var2:integer):integer;stdcall;//就是这句编译出错,奇怪!
    不能放在这里要在IMPL。下面,老大,注意调用 STDCALL CDECLEL啊???
      

  5.   

    这个当然要从外部找
    老大
    因为你没有定义这个函数的执行体
    或是在本单元或是外单元包进来
    你的意思是DLL中的
    就必须加上external "name.dll"
    才行
      

  6.   

    我不太明白你解释的意思,我把delphi代码发给各位,帮我调试一下好吗?
    谢谢。[email protected] oicq:197575
      

  7.   

    //看样了,不贴出来楼主是看不懂
    // 错误的做法
    type
      TForm1 = class(TForm)
        Function add(var1,var2:integer):integer;stdcall;
      private
        ..
      end;
    //正确的做法
    type
      TForm1 = class(TForm)
      private
        ..
      end;
    Function add(var1,var2:integer):integer;stdcall;
    implementation
    function add; external "Mydll.Name" //name "add"