2017-07-13 9 views
1

私はInno Setupスクリプトで作業していますが、アンインストール中にカスタムDLLを呼び出して復帰操作を行います。残念ながら、UnloadDLLとDeleteFileを呼び出したにもかかわらず、アンインストールが完了してDLLが終了し、その依存関係は削除されませんでした。 UnloadDLLが失敗するのはなぜですか? LoadLibraryでDLLダイナミックをロードする可能性はありますか?私はこれに関するいくつかの機能を見てきましたが、それらはすべて廃止されました。Inno Setup:アンインストール時に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

ない本当の問題が何であるかを確認しますが、WindowsのAPIを使用して手動でDLLをアンロード動作します:

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; 
関連する問題