Board index » delphi » Problems unloading DLLs

Problems unloading DLLs

I have a problem unloading DLLs under Windows 95 when the Delphi 2 enviroment is running. If an
application uses a DLL (DLL is compiled with Delphi 2 as well) and this appication terminates in
any way, the DLL and the exe-Module stays in memory. I'm not able to remove them with any tool, the
exe isn't in the task list and therefore can't be termintated too - the only way to go on working
is rebooting.

This happens also, even if I start the application direct from the explorer and Delphi is in
memory - otherwise everything works fine. Has anybody any idea how to solve this problem?

Joerg Wuennemann

 

Re:Problems unloading DLLs


Quote
Joerg Wuennemann wrote:
>I have a problem unloading DLLs under Windows 95 when the Delphi 2 enviroment is running. If an
>application uses a DLL (DLL is compiled with Delphi 2 as well) and this appication terminates in
>any way, the DLL and the exe-Module stays in memory. I'm not able to remove them with any tool, the
>exe isn't in the task list and therefore can't be termintated too - the only way to go on working
>is rebooting.
>This happens also, even if I start the application direct from the explorer and Delphi is in
>memory - otherwise everything works fine. Has anybody any idea how to solve this problem?

I don't know if this will help or not, but just in case ...

I had a similar problem when testing DLLs written in D1.  If (when)
they crashed, they stayed in memory & I had to close Windows.  To
solve the problem, I wrote the prog below.  I added this to my tools
menu, with  $PROMPT in the parameters field.  I have no idea if it
will work in D2, but it may give you an idea of where to start.

program Uldll;

uses
  SysUtils,
  WinTypes,
  WinProcs;

{$R *.RES}

const
  FailText : PChar = ' is not loaded';
var
  hDLL    : THandle;
  Msg     : pChar;
  DLLName : pChar;

begin

  DLLName := StrNew(StrPCopy(nil,ParamStr(0)));

  try
     hDLL := GetModuleHandle(DLLName);

     if hDLL <> 0 then
        while GetModuleUsage(hDLL) > 0 do
           FreeModule(hDLL)
     else begin
        Msg := StrAlloc(  StrLen(DLLName ) +
                          StrLen(FailText) + 1);
        try
           StrCopy(Msg,DLLName);
           StrCat(Msg,FailText);
           MessageBox(0, Msg, 'Unload DLL',mb_OK);
        finally
           StrDispose(Msg);
        end
        end;
  finally
     StrDispose(DLLName);
  end;
end.
Regards,
--
Duncan
LECS Ltd

Other Threads