Search code examples
fileinstallationinno-setuppascalpascalscript

InnoSetup: dll can't be deleted at uninstall


I'm using the VCL Styles provided in this link to skin my installer/uninstaller: https://code.google.com/p/vcl-styles-plugins/wiki/VCLStylesInnoSetup

But when I uninstall the program, the dll that contains the functions is not deleted.

How I can delete it?.

I've thinked about this alternative: Copy the dll to a temporary folder and load that temporary dll that Windows Cleaner should delete in the future, but that causes me another problem that I talk about that in this post: https://stackoverflow.com/questions/26863987/innosetup-pascalscript-filecopy-doesnt-copy But that's another problem, what I would like to know here is how I can delete this dll file.

This is the full [Code] section that I'm using, notice the DeinitializeUninstall method where I try to delete the file:

// Import the LoadVCLStyle function from VclStylesInno.DLL
procedure LoadVCLStyle(VClStyleFile: String); external 'LoadVCLStyleA@files:unins000.dll stdcall setuponly';
procedure LoadVCLStyle_UnInstall(VClStyleFile: String); external 'LoadVCLStyleA@{app}\unins000.dll stdcall uninstallonly';

// Import the UnLoadVCLStyles function from VclStylesInno.DLL
procedure UnLoadVCLStyles; external 'UnLoadVCLStyles@files:unins000.dll stdcall setuponly';
procedure UnLoadVCLStyles_UnInstall; external 'UnLoadVCLStyles@{app}\unins000.dll stdcall uninstallonly';

function InitializeSetup(): Boolean;
begin
    ExtractTemporaryFile('unins000.vsf');
    LoadVCLStyle(ExpandConstant('{tmp}\unins000.vsf'));
    Result := True;
end;

procedure DeinitializeSetup();
begin
    UnLoadVCLStyles;
end;

function InitializeUninstall: Boolean;
begin
    Result := True;
    LoadVCLStyle_UnInstall(ExpandConstant('{app}\unins000.vsf'));
end;

procedure DeinitializeUninstall();
begin
    UnLoadVCLStyles_UnInstall;
    DeleteFile(ExpandConstant('{app}\unins000.dll'));
end;

Solution

  • You need to unload the library before deleting. Use the UnloadDLL function for that (the help contains an example just for this case). Missing that leads the DeleteFile function to fail in your code. For your uninstaller write this instead:

    procedure LoadVCLStyle_UnInstall(VClStyleFile: String); external 'LoadVCLStyleA@{app}\unins000.dll stdcall uninstallonly';
    procedure UnLoadVCLStyles_UnInstall; external 'UnLoadVCLStyles@{app}\unins000.dll stdcall uninstallonly';
    
    function InitializeUninstall: Boolean;
    begin
      Result := True;
      LoadVCLStyle_UnInstall(ExpandConstant('{app}\unins000.vsf'));
    end;
    
    procedure DeinitializeUninstall();
    begin
      UnLoadVCLStyles_UnInstall;
      UnloadDLL(ExpandConstant('{app}\unins000.dll'));
      DeleteFile(ExpandConstant('{app}\unins000.dll'));
    end;