给一个例子,请看下面代码:
library AboutDll;
uses
Forms,
UnitAbout in 'UnitAbout.pas' {Frm_About};
exports
ShowAboutFrm;
begin
end.
Dll窗体代码:
unit UnitAbout;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TSimpleVersion = record
dwProductVersionMS: DWORD;
dwProductVersionLS: DWORD;
end;
TUpdate = record { Structure of update information }
Name:String[63];
Version:TSimpleVersion;
Date:TDate;
URL:ShortString;
end;
TFrm_About = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Bevel1: TBevel;
Label6: TLabel;
Button1: TButton;
Button2: TButton;
Label7: TLabel;
FlatEdit1: TFlatEdit;
FlatEdit2: TFlatEdit;
Label8: TLabel;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ShowAboutFrm(AHandle: THandle; ACaption: string; AName: string); stdcall; //显示关于窗口
implementation
{$R *.dfm}
procedure ShowAboutFrm(AHandle: THandle; ACaption: string; AName: string);
var
Frm_About: TFrm_About;
begin
Application.Handle := AHandle;
Frm_About := TFrm_About.Create(Application);
with Frm_About do
try
Caption := ACaption;
Label1.Caption := AName;
ShowModal;
finally
Free;
end;
end;
procedure TFrm_About.Button2Click(Sender: TObject);
begin
ShowMessage('正在开发中');
end;
end.
调用该Dll例程
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TShowAbout = procedure(AHandle: THandle; ACaption: string; AName: string); StdCall;
EDLLLoadError = class(Exception);
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
LibHandle: THandle;
ShowAbout: TShowAbout;
begin
LibHandle := LoadLibrary('Aboutdll.DLL');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('不能装载动态链接库,请确认动态链接库的存在!');
@ShowAbout := GetProcAddress(LibHandle, 'ShowAboutFrm');
if not (@ShowAbout = nil) then
ShowAbout(Form1.Handle, 'About...','飘摇客通讯录')
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;
end.