Dll释放问题
主窗体:
unit Main
interface
type
TBaseDllShowChild = procedure(ParentApplication: TApplication;ParentForm: TForm;FormName: string; FHanlde: Hwnd); stdcall;
EDllLoadError = class(Exception);
TFrmMain = class(TfrmComMain)
---------------------
---------------------
procedure TFrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
procedure BaseDllShowForm(Sender: TObject;FormName: string; DllName:String);
end;
procedure TFrmMain.BaseDllShowForm(Sender: TObject; FormName,
DllName: String);
var
BaseDllShowChild: TBaseDllShowChild;
begin
BeginShow(Sender);
if BaseDllHandle = 0 then
BaseDllHandle := LoadLibrary(PChar(DllName+'.Dll'));
if BaseDllHandle = 0 then
Raise EDllLoadError.Create('装载动态链接库'+DllName+'.Dll'+'失败!');
@BaseDllShowChild := GetProcAddress(BaseDllHandle,'BaseDllShowChild');
if @BaseDllShowChild <> nil then
BaseDllShowChild(Application,Self,FormName,Application.Handle)
else
RaiseLastWin32Error;
EndShow(Sender);
end;
procedure TFrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
if BaseDllHandle <> 0 then
begin
FreeLibrary(BaseDllHandle);
BaseDllHandle := 0;
end;
Action :=caFree;
end;
Dll:
procedure BaseDllShowChild(ParentApplication: TApplication; ParentForm: TForm;FormName:String;FHandle:Hwnd); export; stdcall;
begin
Application.Handle := FHandle;
Application:=ParentApplication;
FormName := UpperCase(FormName);
if FormName='FRMHRRANK' then
begin
if not Assigned(frmHrRank) then
frmHrRank := TfrmHrRank.Create(ParentForm);
frmHrRank.Show;
end;
end;
procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then
Data.Free;
end;
exports
BaseDllShowChild;
begin
DllName := 'BaseDll';
if not Assigned(Data) then
Data := TData.Create(Application);
DLLProc := @DLLUnloadProc;
end.
----------------------------------------------------------------------------------------
程序采用MDI窗体,能够正常调用DLL中的窗体,但关闭主程序后DLL不能正常释放,还在任务管理器占用11M的内存;请帮忙解决!