type TDllMainForm = class(TForm) procedure FormClose(Sender: TObject; var Action: TCloseAction); private // public // end;////////////////////////=>////////////////////////////////// var DllForm: TDllMainForm; ////////////////////////<=//////////////////////////////////{Declare the export function} function GetDLLForm(app: TApplication): TForm; stdcall;implementation{$R *.dfm}////export function exports GetDllForm;//// 返回DLL中的主窗口对象 function GetDLLForm(app: TApplication): TForm; stdcall; begin Application.Handle:=app.Handle; DllForm:=TDllMainForm.Create(Application); //.MainForm); result := DllForm; end;//// procedure TDllMainForm.FormClose(Sender: TObject; var Action: TCloseAction); begin TDllMainForm(LongInt(Self)).Release; end;end.///////////////////////////////////////////////////////////// // 调用显示DLL中的窗口 procedure TfrmMain.ShowDllMainForm(dllFileName); var DGetDllForm: TDGetDllForm; frm: TForm; begin try //导入DLL库 LibHandle:=LoadLibrary(PChar(dllFileName)); try if LibHandle<>0 then begin //获得DLL中获取DLL主窗口的函数 @DGetDllForm:=GetProcAddress(LibHandle,'GetDLLForm'); if not Assigned(DGetDllForm) then raise Exception.Create('DLL error!'+#13#10+dllFileName); //从DLL中导入DLL主窗口并显示 if not (@DGetDllForm = nil) then begin frm:=DGetDllForm(Application); frm.Show; end; end; finally //FreeLibrary(LibHandle); end; except on E: Exception do MessageDlg(E.Message,mtError,[mbOK],0); end; end;
// DLL 代码
unit frmDllMain_Base;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TDllMainForm = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
//
public
//
end;////////////////////////=>//////////////////////////////////
var
DllForm: TDllMainForm;
////////////////////////<=//////////////////////////////////{Declare the export function}
function GetDLLForm(app: TApplication): TForm; stdcall;implementation{$R *.dfm}////export function
exports
GetDllForm;//// 返回DLL中的主窗口对象
function GetDLLForm(app: TApplication): TForm; stdcall;
begin
Application.Handle:=app.Handle;
DllForm:=TDllMainForm.Create(Application); //.MainForm);
result := DllForm;
end;////
procedure TDllMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TDllMainForm(LongInt(Self)).Release;
end;end./////////////////////////////////////////////////////////////
// 调用显示DLL中的窗口
procedure TfrmMain.ShowDllMainForm(dllFileName);
var
DGetDllForm: TDGetDllForm;
frm: TForm;
begin
try
//导入DLL库
LibHandle:=LoadLibrary(PChar(dllFileName));
try
if LibHandle<>0 then
begin
//获得DLL中获取DLL主窗口的函数
@DGetDllForm:=GetProcAddress(LibHandle,'GetDLLForm');
if not Assigned(DGetDllForm) then
raise Exception.Create('DLL error!'+#13#10+dllFileName); //从DLL中导入DLL主窗口并显示
if not (@DGetDllForm = nil) then
begin
frm:=DGetDllForm(Application);
frm.Show;
end;
end;
finally
//FreeLibrary(LibHandle);
end;
except
on E: Exception do MessageDlg(E.Message,mtError,[mbOK],0);
end;
end;
选上这个好像就没有了!