dll 调用方法有 静态调用和动态调用两种方法
用到的dll为上篇文章所编写的dll.
总结如下:
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TForm1 = Class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Procedure Button1Click(Sender: TObject);
Procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
End;
Var
Form1: TForm1;
Implementation
Function Min(X, Y: Integer): Integer; external 'Project1.dll';
Function Max(X, Y: Integer): Integer; external 'Project1.dll';
procedure SynAPP(App:THandle);stdcall;external 'Project1.dll'; //这里的
procedure ShowForm;stdcall;external 'Project1.dll';
procedure showmyform;stdcall;external 'Project1.dll';
{$R *.dfm}
Procedure TForm1.Button1Click(Sender: TObject);
Begin
showmessage(inttostr(Min(1, 100)));//静态方法
showmessage(inttostr(Max(1, 100)));//静态方法
End;
//动态方法
Procedure TForm1.Button2Click(Sender: TObject);
Type
Tmax = Function(X, Y: Integer): Integer;
THandle = Integer;
Var
mymax: Tmax;
Handle: THandle;
Begin
Handle := LoadLibrary('Project1.dll');
@mymax := GetProcAddress(Handle, 'Max');
showmessage(inttostr(mymax(1, 100)));
FreeLibrary(Handle);
End;
procedure TForm1.Button3Click(Sender: TObject);
begin
// SynAPP(Application.Handle);
showmyform ;//静态方法
//ShowForm ;
end;
End.