Pascal Scripting: UnloadDLL

Inno Setup

Pascal Scripting: UnloadDLL

Prototype:

procedure UnloadDLL(Filename: String);

Description:

Unloads the specified DLL that was loaded by the [Code] section using an "external" keyword. This can be useful if you need to delete the DLL.

The case of the filename and any path name must exactly match that of the function import. You will need to expand any constants in the filename yourself before passing it to UnloadDLL.

If the function import used a "files:" prefix, prepend the value of the {tmp} constant to the filename (e.g. ExpandConstant('{tmp}\filename.dll')).

Remarks:

It's not recommended that you try this, but if you attempt to call a function in a DLL that has been unloaded, the DLL will be re-loaded.

Example:
procedure DllFunc; external 'DllFunc@{app}\MyDll.dll stdcall uninstallonly';

...

begin
  // Call DllFunc
  DllFunc;

  // Unload the DLL
  UnloadDLL(ExpandConstant('{app}\MyDll.dll'));

  // Now we can delete the DLL
  DeleteFile(ExpandConstant('{app}\MyDll.dll'));
end;