DLL封装MDI子窗体

var
  DllApp: TApplication;

procedure MyDllProc(res: Integer);
begin
  case res of
    DLL_PROCESS_ATTACH:
    begin
      CoInitialize(nil);  //如果DLL中用到ADO要加上这句。
      DllApp:= Application;
    end;
    DLL_PROCESS_DETACH:
    begin
      Application:= DllApp;
      CoUninitialize;
    end;   
  end;
end;

function ShowFrm(MainFrm: TForm): Integer; stdcall;
var
  ptr: PLongint;
begin
  ptr:= @(Application.MainForm);
  ptr^:= LongInt(MainFrm);
  ChildMDIFrm:= TChildMDIFrm.Create(MainFrm);
  ChildMDIFrm.Show;
  Result:= 1;
end; 

exports
  ShowFrm;

begin
  DllProc:= @MyDllProc;
  MyDllProc(DLL_PROCESS_ATTACH);
end.

你可能感兴趣的:(dll)