Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

pascalscript - Load external DLL for uninstall process in Inno Setup

I'm trying to load VclStylesInno.dll for uninstall form of Inno Setup. Next code is declared in the middle of [Code] section:

procedure uLoadVCLStyle(VClStyleFile: String);
    external 'LoadVCLStyleW@{app}/VclStylesInno.dll stdcall';

but I faced an error

An attempt was made to expand the "app" constant before it was initialized

What is the best way to load DLL for uninstall process?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I assume you are getting the error, when starting the installer, not the uninstaller.

When the installer is starting, the {app} is obviously unknown yet.

But as you need the import for the uninstaller only, which knows the {app}, you can add the uninstallonly option:

procedure uLoadVCLStyle(VClStyleFile: String); 
  external 'LoadVCLStyleW@{app}VclStylesInno.dll stdcall uninstallonly';

Though it does not really help, as the uninstaller will want to remove the DLL, failing, as it has the DLL locked itself.

The solution is simple, just follow the official instructions for uninstalling the VCL Styles for Inno Setup.

You basically need to install the DLL somewhere else than in the {app} and leave the DLL behind when uninstalling. That's actually an ugly solution, which imho does not justify a styled uninstaller. But it's your choice.


As you suggested, you may copy the DLL to Windows temporary folder, load it from there and hope for Windows to eventually delete the DLL during temporary directory cleanup.

This should do (note the delayload option):

[Files]
Source: VclStylesInno.dll; DestDir: {app}
Source: skin.vsf; DestDir: {app}
[Code]

procedure LoadVCLStyle_UnInstall(VClStyleFile: String); 
  external 'LoadVCLStyleW@{%TEMP}VclStylesInno.dll stdcall uninstallonly delayload';

function InitializeUninstall: Boolean;
begin
  if FileCopy(ExpandConstant('{app}VclStylesInno.dll'),
              ExpandConstant('{%TEMP}VclStylesInno.dll'), False) and
     FileCopy(ExpandConstant('{app}skin.vsf'),
              ExpandConstant('{%TEMP}skin.vsf'), False) then
  begin
    LoadVCLStyle_UnInstall(ExpandConstant('{%TEMP}skin.vsf'));
  end;
end;

While I didn't test it, it might be better to use {tmp} instead of {%TEMP} (the files might get deleted by the uninstaller parent process right after the uninstallation finishes – and you won't interfere with other processes that might want to store VclStylesInno.dll to %TEMP%).


For another solution (better but more complicated to implement), see
How keep uninstall files inside uninstaller?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...