//DLL: FunLib.DLL
library FunLib;
uses
SysUtils,
Classes,
About in 'About.pas' {AboutForm};
{$R *.RES}
exports
AboutBox, //Show about box.
begin
end.
//About.pas
unit About;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, jpeg, ComCtrls;
type
TAboutForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
AboutForm: TAboutForm;
procedure AboutBox (AHandle: THandle; Caption, FileName: Pchar); stdcall;
implementation
{$R *.DFM}
procedure AboutBox(AHandle : THandle; Caption, FileName: Pchar);
var
AboutForm : TAboutForm;
OldApplication : TApplication;
begin
{Assign the application's handle that call DLL to DLL's handle.}
OldApplication := TApplication.Create(Application);
OldApplication.Handle := Application.Handle;
Application.Handle := AHandle;
{Create and show logon form.}
AboutForm := TAboutForm.Create(Application);
try
AboutForm.Caption := Caption;
AboutForm.fcLabel1.Caption := Caption;
AboutForm.ShowModal;
finally
AboutForm.Free;
Application.Handle := OldApplication.Handle; //Recall application that call DLL.
end;
end;
end.
//CALL AboutBox
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TAboutForm = procedure(AHandle: THandle; Caption, FileName: Pchar); stdcall;
TForm1 = class(TForm)
Button6: TButton;
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button6Click(Sender: TObject);
var
AHandle: THandle;
AboutBox: TAboutForm;
begin
AHandle := LoadLibrary('FunLib.dll');
try
if AHandle = 0 then
showmessage('无法装入FunLib.Dll。')
else begin
@AboutBox := GetProcAddress(AHandle, 'AboutBox');
AboutBox(Application.Handle, PChar('Test'), 'kk.txt');
end;
finally
FreeLibrary(AHandle);
end;
end;
end.