CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  语言基础/算法/系统设计

怎样释放DLL中的MDI窗体比较好

楼主guolinchao(kony)2003-11-03 23:57:19 在 Delphi / 语言基础/算法/系统设计 提问

问题如上.  
   
  //主程序  
  procedure   mxSC;  
  var  
        HDL:THandle;  
        vFileName:String;  
        ShowMDIForm:TmdlShowMDIForm;  
  begin  
        vFileName:=ExtractFileDir(Application.ExeName)   +   '\Module\mSC.dll';  
        HDL:=LoadLibrary(PChar(vFileName));  
        if   HDL   <=   0   then   begin  
              Raise   Exception.Create('加载'   +   vFileName   +   '失败!');  
              Exit;  
        end;  
        try  
              @ShowMDIForm:=GetProcAddress(HDL,Pchar('ShowMDIForm'));  
              if   not   Assigned(ShowMDIForm)   then  
                    Raise   Exception.Create('读取'   +   vFileName   +   'ShowMDIForm函数入口指针失败')  
              else  
                    ShowMDIForm(Application,Application.MainForm);  
        finally  
              //*******************************************************  
              FreeLibrary(HDL);//不加该句,关闭MDI窗体时怎样释放装载的DLL。  
              //*******************************************************  
        end;  
  end;  
   
   
  library   mSC;  
  {$DEFINE   VENDORLL}  
   
  uses  
      SysUtils,  
      Classes,  
      windows,  
      Forms,  
      ActiveX,  
      SC   in   '..\SC.pas'   {frmSC},  
      SCEdit   in   '..\SCEdit.pas'   {frmSCEdit},  
      SCServer   in   '..\SCServer.pas'   {dmSCServer:   TDataModule};  
  var  
        DLLApplication:TApplication;  
  {$R   *.res}  
   
   
  procedure   DllEntryPoint(dwReason:DWORD);register;  
  begin  
      case   dwReason   of  
          DLL_PROCESS_ATTACH:   DLLApplication:=Application;  
          DLL_PROCESS_DETACH:   Application:=DLLApplication;  
      end;  
  end;  
   
  function   ShowMDIForm(ParentApplication:TApplication;ParentForm:TForm):LongInt;export;stdcall;  
  begin  
        Application:=ParentApplication;  
        if   not   Assigned(dmSCServer)   then   dmSCServer:=TdmSCServer.Create(Application);  
        if   not   Assigned(frmSC)   then   frmSC:=TfrmSC.Create(ParentForm);  
        Result:=LongInt(frmSC);  
        dmSCServer.GetSCAllData;  
        Windows.SetParent(frmSC.Handle,ParentForm.Handle);  
        frmSC.FormStyle:=fsMDIChild;  
        frmSC.Show;  
  end;  
   
  exports  
        ShowMDIForm;  
   
  begin  
        CoInitialize(nil);    
        DllProc:=@DllEntryPoint;  
        DllEntryPoint(DLL_PROCESS_ATTACH);  
  end.  
   
   
   
  //DLL中的MDI  
   
  type  
        TmdlShowMDIForm=function   (ParentApplication:TApplication;ParentForm:TForm):LongInt;stdcall;  
     
   
  procedure   TfrmSC.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  begin  
        Action:=caFree;  
        frmSC:=nil;  
  end;  
   
  问题点数:20、回复次数:6Top

1 楼guolinchao(kony)回复于 2003-11-04 11:47:00 得分 0

对不起,写错了。  
   
              由于时调用非模式窗体,所有,不可以用FreeLibrary()函数释放DLL的资源。  
              请问怎样在主程序或者在DLL中怎样释放资源。  
   
  //主程序  
  type  
        TmdlShowMDIForm=function       (ParentApplication:TApplication;ParentForm:TForm):LongInt;stdcall;  
   
  //调用DLL中的MDI过程  
  procedure   mxSC;  
  var  
        HDL:THandle;  
        vFileName:String;  
        ShowMDIForm:TmdlShowMDIForm;  
  begin  
        vFileName:=ExtractFileDir(Application.ExeName)   +   '\Module\mSC.dll';  
        HDL:=LoadLibrary(PChar(vFileName));  
        if   HDL   <=   0   then   begin  
              Raise   Exception.Create('加载'   +   vFileName   +   '失败!');  
              Exit;  
        end;  
        try  
              @ShowMDIForm:=GetProcAddress(HDL,Pchar('ShowMDIForm'));  
              if   not   Assigned(ShowMDIForm)   then  
                    Raise   Exception.Create('读取'   +   vFileName   +   'ShowMDIForm函数入口指针失败')  
              else  
                    ShowMDIForm(Application,Application.MainForm);  
        finally  
              //*******************************************************  
              //由于时调用非模式窗体,所有,不可以用FreeLibrary()函数释放DLL的资源。  
              //请问怎样在主程序或者在DLL中怎样释放资源。  
              //*******************************************************  
        end;  
  end;  
   
   
  //-------------------------------------DLL  
   
  library   mSC;  
  {$DEFINE   VENDORLL}  
   
  uses  
      SysUtils,  
      Classes,  
      windows,  
      Forms,  
      ActiveX,  
      SC   in   '..\SC.pas'   {frmSC},  
      SCEdit   in   '..\SCEdit.pas'   {frmSCEdit},  
      SCServer   in   '..\SCServer.pas'   {dmSCServer:   TDataModule};  
  var  
        DLLApplication:TApplication;  
  {$R   *.res}  
   
   
  procedure   DllEntryPoint(dwReason:DWORD);register;  
  begin  
      case   dwReason   of  
          DLL_PROCESS_ATTACH:   DLLApplication:=Application;  
          DLL_PROCESS_DETACH:   Application:=DLLApplication;   //可以在此释放吗,这么做?我试过在此释放,但失败了!  
      end;  
  end;  
   
  function   ShowMDIForm(ParentApplication:TApplication;ParentForm:TForm):LongInt;export;stdcall;  
  begin  
        Application:=ParentApplication;  
        if   not   Assigned(dmSCServer)   then   dmSCServer:=TdmSCServer.Create(Application);  
        if   not   Assigned(frmSC)   then   frmSC:=TfrmSC.Create(ParentForm);  
        Result:=LongInt(frmSC);  
        dmSCServer.GetSCAllData;  
        Windows.SetParent(frmSC.Handle,ParentForm.Handle);  
        frmSC.FormStyle:=fsMDIChild;  
        frmSC.Show;  
  end;  
   
  exports  
        ShowMDIForm;  
   
  begin  
        CoInitialize(nil);    
        DllProc:=@DllEntryPoint;  
        DllEntryPoint(DLL_PROCESS_ATTACH);  
  end.  
   
  //DLL中的MDI是这样释放的  
  procedure   TfrmSC.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  begin  
        Action:=caFree;  
        frmSC:=nil;  
  end;  
  Top

2 楼guolinchao(kony)回复于 2003-11-04 22:33:52 得分 0

怎样及时的释放DLL资源,  
  procedure   DllEntryPoint(dwReason:DWORD);register;  
  begin  
      case   dwReason   of  
          DLL_PROCESS_ATTACH:   DLLApplication:=Application;  
          DLL_PROCESS_DETACH:   Application:=DLLApplication;   //这句只有当主调程序关闭时才执行,我想当关闭MDI   Form   时就释放,怎么做呢?  
      end;  
  end;Top

3 楼guolinchao(kony)回复于 2003-11-05 16:55:41 得分 0

怎么没人回答呢?Top

4 楼deepWATERblue(深水蓝)回复于 2003-11-05 17:58:35 得分 0

qiang.Top

5 楼saien(精益求精)回复于 2003-11-05 18:59:46 得分 20

在dll中释放比较Top

6 楼guolinchao(kony)回复于 2003-11-05 22:21:27 得分 0

但是,在DLL中怎么释放呢?  
  这个问题已经两天了,还是没有解决,如果会就帮帮我吧!Top

相关问题

  • 如何使dll的窗体成为当前MDI窗体的MDIChild窗体
  • 如何将DLL中的窗体显示在mdi窗体中?
  • 在DLL中怎样调用MDI窗体
  • fastreport在MDI窗体的DLL中报错!
  • DLL中使用MDI窗体的问题?
  • Mdi窗体加载新的子窗体时候如何释放原来的子窗体
  • 源码相送!!从MDI中的子窗体,调用DLL中的子窗体!
  • 请问active dll工程中的窗体如何才能作为主工程中MDI窗体的子窗体?
  • MDI窗体
  • MDI中子窗体的内存释放问题(菜鸟问题)

关键词

  • dll
  • vfilename
  • hdl

得分解答快速导航

  • 帖主:guolinchao
  • saien

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo