在Inno Setup中将依赖项加载DLL在卸载程序中显示“无法导入DLL"失败,但在安装程序中有效 [英] Loading DLL with dependencies in Inno Setup fails in uninstaller with "Cannot import DLL", but works in the installer

查看:177
本文介绍了在Inno Setup中将依赖项加载DLL在卸载程序中显示“无法导入DLL"失败,但在安装程序中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

卸载程序时出现此错误:

When I uninstall the program I get this error:

无法导入dll:< utf8> c:\ TestProg \ IsStart.dll

Cannot import dll: <utf8>c:\TestProg\IsStart.dll

我在这里做错了什么?有人可以帮我解决这个问题吗?

What have I done wrong here? Can anybody help me to solve this problem?

CheckO4TaskMngrSvcStopAndUninstall 停止并删除 O4TaskManager服务:

代码如下:

[Files]
Source: "IsStartServer.dll"; DestDir: "{tmp}"; DestName: IsStart.dll
Source: "IsStartServer.dll"; DestDir: "{app}"; DestName: IsStart.dll
Source: "sqlite3x86.dll"; DestDir: "{src}"; DestName: sqlite3.dll
Source: "sqlite3x86.dll"; DestDir: "{app}"; DestName: sqlite3.dll
Source: "sqlite3x64.dll"; DestDir: "{app}"

[Code]
function TaskMngrInst: LongBool;                                                
external 'CheckO4TaskMngrSvcStopAndUninstall@files:IsStart.dll,sqlite3.dll stdcall loadwithalteredsearchpath setuponly';

function TaskMngrUninst: LongBool;                                                
external 'CheckO4TaskMngrSvcStopAndUninstall@{app}\IsStart.dll stdcall uninstallonly';

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
    begin
      TaskMngrInst();
    end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
    begin
      TaskMngrUninst();
      DeleteFile(ExpandConstant('{app}\sqlite3.dll'));
      DeleteFile(ExpandConstant('{app}\IsStart.dll'));
      RenameFile('{app}\sqlite3x64.dll)', '{app}\sqlite3.dll');
    end;
end;

推荐答案

我认为存在一系列不同的问题(其中某些确实是基于我的错误建议).

I believe there was series of different problems (some of which were indeed based on my wrong suggestions).

正确的代码是imo:

[Files]
Source: "IsStartServer.dll"; DestDir: "{app}"; DestName: IsStart.dll
Source: "sqlite3x86.dll"; DestDir: "{app}"; DestName: sqlite3.dll

[Code]
function TaskMngrInst: LongBool;                                                
  external 'CheckO4TaskMngrSvcStopAndUninstall@files:IsStart.dll,sqlite3.dll stdcall loadwithalteredsearchpath setuponly';

function TaskMngrUninst: LongBool;                                                
  external 'CheckO4TaskMngrSvcStopAndUninstall@{app}\IsStart.dll stdcall loadwithalteredsearchpath uninstallonly';

要点:

  • 您最初的问题是缺少 loadwithalteredsearchpath 标志.您需要它来加载依赖项( sqlite3.dll ).
  • 您需要将依赖项( sqlite3.dll )安装到 {app} 中,以供卸载程序使用.
  • 已安装的依赖项副本必须与主DLL查找的名称匹配( sqlite3.dll ,而不是 sqlite3x86.dll ).
  • external 声明中的DLL名称必须与目标文件名相匹配( DestName:IsStart.dll DestName:sqlite3.dll ),而不是原始版本.
  • 仅当从安装程序(带有 files:前缀)中加载DLL时,依赖关系才必须并且可以在声明中列出.从物理路径( {app} \ IsStart.dll )加载DLL时不可以.列出依赖项的唯一目的是让安装程序提取它(它不会加载它,主DLL会加载它,因此是上一点).加载物理文件时,无需列出它,因为已经(必须)安装了所有文件.如果您使用 {app} \ primary.dll,{app} \ dependency.dll ,则卸载程序实际上将尝试加载名称为 {app} \ primary.dll,{app} \ dependency.dll –显然失败.
  • 没有必要在 {tmp} {src} 上安装任何内容.
  • Your original problem was the lack of loadwithalteredsearchpath flag in the import declaration for the uninstaller. You need it to load the dependencies (sqlite3.dll).
  • You need to install the dependencies (sqlite3.dll) to the {app} for the use by the uninstaller.
  • The installed copy of the dependency has to match the name the primary DLL looks for (sqlite3.dll, not sqlite3x86.dll).
  • The name of the DLLs in the external declaration has to match the destination filename (DestName: IsStart.dll, DestName: sqlite3.dll), not the original one.
  • The dependency must and can be listed in the declaration only when loading the DLLs from within the installer (with the files: prefix). Not when loading the DLL from a physical path ({app}\IsStart.dll). The sole purpose for listing the dependency is for the installer to extract it (it does not load it, the primary DLL does, hence the the previous point). You do not need to list it, when loading physical files, as all files are (must be) installed already. If you use {app}\primary.dll,{app}\dependency.dll, the uninstaller will actually try to load a file with a name {app}\primary.dll,{app}\dependency.dll – obviously failing.
  • There's no point installing anything to {tmp} nor {src}.

这篇关于在Inno Setup中将依赖项加载DLL在卸载程序中显示“无法导入DLL"失败,但在安装程序中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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