2017-07-13 103 views
1

我正在使用Inno安装脚本并在卸载过程中调用自定义DLL来执行一些还原操作。不幸的是,卸载完成后,DLL和它的依赖不会被删除,尽管我调用了UnloadDLL和DeleteFile。 为什么UnloadDLL失败? 有没有可能使用LoadLibrary加载动态链接库?我已经看到了一些这方面的功能,但它们都被弃用了。Inno安装程序:UnloadDLL在卸载时不起作用

下面的代码:

function Revert(param: String): cardinal; 
external '[email protected]{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; 
+0

是什么'DeleteFile'返回? –

+0

它返回false。 – dJonzo

+0

请注意:'StringChangeEx(dataDirectory,'\','\\',True);'有点危险。如果“\\”已经存在于'dataDirectory'中,结果将是“\\\\”! –

回答

1

不知道什么是真正的问题,但卸载DLL与手动安装Windows API的工作原理:

function GetModuleHandle(moduleName: String): LongWord; 
external '[email protected] stdcall'; 

function FreeLibrary(module: LongWord): Integer; 
external '[email protected] stdcall'; 

var 
    lib: LongWord; 
    res: integer; 

repeat 
    lib := GetModuleHandle('Revert.dll'); 
    res := FreeLibrary(lib); 
until res = 0; 
相关问题