Not much said, look at the code should understand, once I encountered problems, now let everyone share!
Here is the part of the engineering document:
Encapsulating an MDI child form in a DLL requires you to override the DLL entry function, as shown in the following code:
1var
2 DllApp: TApplication;//定义保存原DLL的TApplication对象
3 DllScr: TScreen;//定义保存原DLL的TScreen对象
4
5procedure UnProcDll(Reason: Integer); register;
6//重新定义DLL入口函数
7begin
8 if Reason = DLL_PROCESS_DETACH then
9 begin
10 Application := DllApp;
11 Screen := DllScr;
12 end;
13end;
14
15//初始化区
16begin
17 DllApp := Application;//备份原DLL的TApplication对象
18 DllScr := Screen;//备份原DLL的TScreen对象
19 DllProc := @UnProcDll;//将重写后的入口函数地址付给DLLProc
20end.
Here is the function to be exported, written in the engineering file or in the interface section of a unit:
1function ShowForm(App: TApplication; Scr: TScreen; Owner: TForm):TForm; export; stdcall;
2begin
3 //下面的这两个变量是必须的
4 Application := App;//这个就是调用的时候对Application对象重新赋值
5 Screen := Scr;//对Screen对象赋值
6 //函数自定义代码
7 if not Assigned(Form1) then
8 begin
9 //Application.CreateForm(TForm1, Form1);
10 Form1 := TForm1.Create(Owner);
11 Result := Form1;
12 end
13 else
14 Result := Form1;
15 //函数自定义代码结束
16end;
Finally, in the engineering file to export this function is OK.
1//最后导出这个函数
2exports
3 ShowForm;