kbmMWGlobal in DLL hangs in when DLL is unloaded 5.23

Home Forums kbmMW kbmMWGlobal in DLL hangs in when DLL is unloaded 5.23

Viewing 1 reply thread
  • Author
    Posts
    • #57947
      mrluigi2017
      Participant

      Hi Kim,

      We noticed that when the kbmMWGlobal is included in the uses of a DLL the application that uses the DLL will hang when it tries to unload it.

      DLL Code:

      library DllWithKbmMw;
      
      {KbmMw source folder is in search path of project}
      
      uses
        kbmMWGlobal;
      
      {$R *.res}
      
      begin
      end.

      Exe Code:

      unit Main;
      
      {
      
        Unloading DllWithKbmMw.dll is hanging.
      
      }
      
      interface
      
      uses
        Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
        Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
      
      type
      
        TMainForm = class(TForm)
          LoadBtn: TButton;
          UnloadBtn: TButton;
          procedure LoadBtnClick(Sender: TObject);
          procedure UnloadBtnClick(Sender: TObject);
          procedure FormCreate(Sender: TObject);
        private
          { Private declarations }
          FDllH: THandle;
          procedure UpdateButtons;
        public
          { Public declarations }
        end;
      
      var
        MainForm: TMainForm;
      
      implementation
      
      {$R *.dfm}
      
      uses
        System.UITypes;
      
      procedure TMainForm.FormCreate(Sender: TObject);
      begin
        UpdateButtons;
      end;
      
      procedure TMainForm.LoadBtnClick(Sender: TObject);
      var
        DllFn: string;
      begin
        if FDllH=0 then
        begin
          DllFn:=IncludeTrailingPathDelimiter(ExtractFileDir(Application.ExeName))+
            'DllWithKbmMw.dll';
          FDllH:=LoadLibrary(PChar(DllFn));
          if FDllH=0 then
            raise Exception.Create('Error loading DLL: '+SysErrorMessage(GetLastError));
          UpdateButtons;
          MessageDlg('DLL loaded',TMsgDlgType.mtInformation,[mbOk],0);
        end;
      end;
      
      procedure TMainForm.UnloadBtnClick(Sender: TObject);
      begin
        if FDllH<>0 then
        begin
          FreeLibrary(FDllH);//This will hang (in kbmMWFinalize)
          FDllH:=0;
          UpdateButtons;
          MessageDlg('DLL unloaded',TMsgDlgType.mtInformation,[mbOk],0);
        end;
      end;
      
      procedure TMainForm.UpdateButtons;
      begin
        LoadBtn.Enabled:=FDllH=0;
        UnLoadBtn.Enabled:=FDllH<>0;
      end;
      
      end.

      The problem is somewhere in the finalization of the unit, but we couldn’t pinpoint where it goes wrong exactly.

      Could you please look into this!

      Thanks in advance!

      Kind regards Luigi

    • #58258
      kimbomadsen
      Keymaster

      I think the problem has been solved in 5.24.00 by rewriting the kbmMWDependency package and cleaning up dependencies.

      /Kim/C4D

Viewing 1 reply thread
  • You must be logged in to reply to this topic.