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?
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}
[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) then
begin
LoadVCLStyle_UnInstall(...);
end;
end;
For another solution (better but more complicate to implement), see How keep uninstall files inside uninstaller?