2017-07-13 104 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; 
相關問題