在Inno Setup中加载用于卸载过程的外部DLL [英] Load external DLL for uninstall process in Inno Setup

查看:237
本文介绍了在Inno Setup中加载用于卸载过程的外部DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载VclStylesInno.dll以进行Inno Setup的卸载形式. 在[Code]部分的中间声明下一个代码:

I'm trying to load VclStylesInno.dll for uninstall form of Inno Setup. Next code is declared in the middle of [Code] section:

procedure uLoadVCLStyle(VClStyleFile: String);
    external 'LoadVCLStyleW@{app}/VclStylesInno.dll stdcall';

但我遇到了错误

尝试在初始化"app"常量之前对其进行扩展

An attempt was made to expand the "app" constant before it was initialized

为卸载过程加载DLL的最佳方法是什么?

What is the best way to load DLL for uninstall process?

推荐答案

我认为您在启动安装程序而不是卸载程序时遇到错误.

I assume you are getting the error, when starting the installer, not the uninstaller.

启动安装程序时,{app}显然还是未知的.

When the installer is starting, the {app} is obviously unknown yet.

但是,由于您只需要导入知道{app}的卸载程序,因此可以添加 uninstallonly选项:

But as you need the import for the uninstaller only, which knows the {app}, you can add the uninstallonly option:

procedure uLoadVCLStyle(VClStyleFile: String); 
  external 'LoadVCLStyleW@{app}\VclStylesInno.dll stdcall uninstallonly';

尽管它并没有真正的帮助,因为卸载程序将锁定DLL,因此卸载程序将要删除DLL,但失败了.

Though it does not really help, as the uninstaller will want to remove the DLL, failing, as it has the DLL locked itself.

解决方案很简单,只需遵循官方

The solution is simple, just follow the official instructions for uninstalling the VCL Styles for Inno Setup.

您基本上需要将DLL安装在{app}以外的其他位置,并在卸载时将DLL留在后面.这实际上是一个丑陋的解决方案,imho并不能证明样式化的卸载程序是合理的.但这是您的选择.

You basically need to install the DLL somewhere else than in the {app} and leave the DLL behind when uninstalling. That's actually an ugly solution, which imho does not justify a styled uninstaller. But it's your choice.

按照您的建议,您可以将DLL复制到Windows临时文件夹,从那里加载它,并希望Windows最终在清理临时目录期间删除DLL.

As you suggested, you may copy the DLL to Windows temporary folder, load it from there and hope for Windows to eventually delete the DLL during temporary directory cleanup.

这应该做(请注意 delayload选项):

This should do (note the delayload option):

[Files]
Source: VclStylesinno.dll; DestDir: {app}
Source: skin.vsf; DestDir: {app}

[Code]

procedure LoadVCLStyle_UnInstall(VClStyleFile: String); 
  external 'LoadVCLStyleW@{%TEMP}\VclStylesInno.dll stdcall uninstallonly delayload';

function InitializeUninstall: Boolean;
begin
  if FileCopy(ExpandConstant('{app}\VclStylesinno.dll'),
              ExpandConstant('{%TEMP}\VclStylesinno.dll'), False) and
     FileCopy(ExpandConstant('{app}\skin.vsf'),
              ExpandConstant('{%TEMP}\skin.vsf'), False) then
  begin
    LoadVCLStyle_UnInstall(ExpandConstant('{%TEMP}\skin.vsf'));
  end;
end;

虽然我没有对其进行测试,但最好使用 {tmp} 而不是{%TEMP}(卸载完成后,文件可能会被卸载程序的父进程删除-并且您不会干扰其他可能要将VclStylesinno.dll存储到).

While I didn't test it, it might be better to use {tmp} instead of {%TEMP} (the files might get deleted by the uninstaller parent process right after the uninstallation finishes – and you won't interfere with other processes that might want to store VclStylesinno.dll to %TEMP%).

有关另一种解决方案(实施起来更好,但更复杂),请参见
如何将卸载文件保留在卸载程序中?

For another solution (better but more complicated to implement), see
How keep uninstall files inside uninstaller?

这篇关于在Inno Setup中加载用于卸载过程的外部DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆