【发布时间】:2017-12-18 07:01:36
【问题描述】:
我正在编写一个 Inno Setup 脚本,在卸载过程中我调用了一个自定义 DLL 来执行一些 Revert 操作。不幸的是,卸载完成后,DLL 和它的依赖项并没有被删除,尽管我调用了UnloadDLL 和 DeleteFile(它返回False)。
为什么UnloadDLL 会失败?
是否有可能使用LoadLibrary 加载动态DLL?我已经看到了一些与此相关的功能,但它们都已被弃用。 DLL 是用带有 C 接口的 Visual Studio 构建的。
代码如下:
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;
【问题讨论】:
标签: dll inno-setup uninstallation delete-file