library Project1;uses ShareMem, Forms, Windows, SysUtils, Classes, Unit1 in 'Unit1.pas' {Form1};{$R *.res}var DllApp: TApplication;//定义保存原DLL的TApplication对象 DllScr: TScreen;//定义保存原DLL的TScreen对象function ShowForm(App: TApplication;
Scr: TScreen;
Owner: TForm):TForm;
export;
stdcall;
begin
Application := App;
Screen := Scr;
if not Assigned(Form1) then
begin
Form1 := TForm1.Create(Owner);
Form1.Show;
end else
Form1.Show;
Result := nil;
end;
procedure UnProcDll(Reason: Integer);
register;//定义DLL处理过程begin
if (Reason = DLL_PROCESS_DETACH) OR (Reason = DLL_THREAD_DETACH) then
begin
Application := DllApp;
Screen := DllScr;
end;
end;
exports ShowForm;
begin
DllApp := Application;//备份原DLL的TApplication对象 DllScr := Screen;//备份原DLL的TScreen对象 DllProc := @UnProcDll;//将重写后的入口函数地址付给DLLProcend.