Dll释放问题

coeltdit coeltdit 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
主窗体:
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的内存;请帮忙解决!
...全文

相关推荐

评论 22
收藏 已收藏
分享
返回顶部
coeltdit
数据库相关 2,508 成员 88,437 内容