主要需要做的,其实就只有一件事,那就是修复DLL的入口
流程如下:
新建一个dll,然后添加一个Form,并把FormStyle设为MDIChild。
然后写以下的代码即可:
01 library MDIDll;
02
03 uses
04 Windows,
05 SysUtils,
06 Forms,
07 Classes,
08 frmMDI in 'frmMDI.pas' {FormMDI};
09
10 {$R *.res}
11
12 var
13 DllApp: TApplication;
14 DllScr: TScreen;
15
16 procedure CreateMDIForm(AApp: TApplication; AScrn: TScreen); stdcall;
17 begin
18 Application := AApp;
19 Screen := AScrn;
20 if FormMDI = nil then
21 FormMDI := TFormMDI.Create(AApp);
22 end;
23
24 procedure DLLUnloadProc(Reason: Integer); register;
25 begin
26 if (Reason = DLL_PROCESS_DETACH) or (Reason = DLL_THREAD_DETACH) then
27 begin
28 Application := DllApp;
29 Screen := DllScr;
30 end;
31 end;
32
33 exports
34 CreateMDIForm;
35
36 begin
37 DllApp := Application;
38 DllScr:= Screen;
39 DllProc := @DLLUnloadProc;
40 end.
然后写个简单的Host,FormStyle设为MDIForm,然后代码也很简单:
01 unit frmTest;
02
03 interface
04
05 uses
06 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
07 Dialogs, Menus;
08
09 type
10 TForm1 = class(TForm)
11 MainMenu1: TMainMenu;
12 CreateMDIForm1: TMenuItem;
13 procedure CreateMDIForm1Click(Sender: TObject);
14 private
15
16 public
17 { Public declarations }
18 end;
19
20 var
21 Form1: TForm1;
22
23 procedure CreateMDIForm(AApp: TApplication; AScrn: TScreen); stdcall; external 'MDIDll.dll';
24
25 implementation
26
27 {$R *.dfm}
28
29 procedure TForm1.CreateMDIForm1Click(Sender: TObject);
30 begin
31 CreateMDIForm(Application, Screen);
32 end;
33
34 end.