library Project1;
uses
ComServ,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.RES}
function InitDll:boolean; stdcall;
begin
try
Form1:=TForm1.Create(nil);
form2:=TForm2.Create(nil);
result:=true;
except
result:=false;
end;
end;
function ShowForm(const iForm:SmallInt):Boolean; stdcall;
begin
InitDll;
if iForm=0 then
form1.Show
else
form2.Show;
end;
exports
ShowForm;
begin
end.
调用
unit test;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TtestForm = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowForm(const iForm:SmallInt):Boolean; stdcall;external 'Project1.dll';
var
testForm: TtestForm;
implementation
{$R *.dfm}
procedure TtestForm.Button1Click(Sender: TObject);
begin
ShowForm(0);
end;
procedure TtestForm.Button2Click(Sender: TObject);
begin
ShowForm(1);
end;
end.