以下是比较三个数最大值的一个DLL,如何用动态调用?
library max;
uses
  SysUtils,
  Classes;
{$R *.res}
function max1(a,b,c:integer):integer;stdcall;
var t:integer;
  begin
  if a>b then t:=a
  else t:=b;
  if t>c then result:=t
  else result:=c;
  end;
  exports
  max1;
begin
end.主程序有四个框,Edit1,Edit2,Edit3为输入框,Edit4为输出框,一个BUTTON1按钮,如何操作,麻烦贴出全部代码,新手还不是太理解原理,谢谢!

解决方案 »

  1.   


    procedure TForm1.Button1Click(Sender: TObject); 
    type 
    TIntFunc=function(a,b,c:integer):integer;stdcall; 
    var 
    Th:Thandle; 
    Tf:TIntFunc; 
    Tp:TFarProc; 
    begin 
    Th:=LoadLibrary(’max.dll’); {装载DLL} 
    if Th>0 then 
    try 
    Tp:=GetProcAddress(Th,PChar(’max1’)); 
    if Tp<>nil 
    then begin 
    Tf:=TIntFunc(Tp); 
    Edit4.Text:=IntToStr(Tf(strtoint(Edit1.Text),strtoint(Edit2.Text),strtoint(Edit3.Text))); {调用max1函数} 
    end 
    else 
    ShowMessage(’max1函数没有找到’); 
    finally 
    FreeLibrary(Th); {释放DLL} 
    end 
    else 
    ShowMessage(’max.dll没有找到’); 
    end;
      

  2.   

    静态调用
    在调用的里面加入声明
    function max1(a,b,c:integer):integer;stdcall; external 'xxxx.dll'然后就可以直接使用函数了
      

  3.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Edit4: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      function max1(a,b,c:integer):integer;stdcall;external 'max1.dll' name 'max1';
    var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      a,b,c:integer;
    begin
      a:=strtoint(edit1.Text);
      b:=strtoint(edit2.Text);
      c:=strtoint(edit3.Text);
      edit4.Text:=inttostr(max1(a,b,c));
    end;end.