I'm working on an Inno Setup script and during uninstall I call a custom DLL to do some Revert operation. Unfortunately, after uninstall is completed the DLL and it's dependencies were not removed, despite the fact I called UnloadDLL
and DeleteFile (which returns False
).
Why does UnloadDLL
fail?
Is there a possibility to load the DLL dynamic with LoadLibrary
? I have seen some functions regarding this, but they are all deprecated. The DLL is built with Visual Studio with C interface.
Here's the code:
function Revert(param: String): cardinal;
external 'Revert@{app}\Revert.dll cdecl delayload uninstallonly';
procedure RevertAll();
var
param: String;
dataDirectory: String;
temp: String;
i: Integer;
begin
dataDirectory := ExpandConstant('{commonappdata}\MyAppData');
StringChangeEx(dataDirectory, '\', '\\', True);
param := '{"dataDirectory": "' + dataDirectory + '", "registryPath" : "SOFTWARE\\MyReg\\Key"}';
Revert(param);
temp := ExpandConstant('{app}\Revert.dll');
for i := 0 to 10 do
begin
UnloadDLL(temp);
Sleep(500);
if DeleteFile(temp) then
break;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if (CurUninstallStep = usUninstall) then
begin
RevertAll();
end
end;