在InnoSetup中使用外部Lib

时间:2014-12-29 14:08:32

标签: installation inno-setup

我在inno设置中使用外部库,我通过Stdcall调用。

[Files]
Source: ZipLib.dll; DestDir: {tmp}; Flags: dontcopy
...
[Code]
function ReadZipEx(archivePath:String; outputPath:String; callback:longword): longword;
external 'ReadZipEx@files:ZipLib.dll stdcall';

因为库有一些依赖项我想将库放在setup.exe下面的某个目录中并使用它而不将其添加到[Files]。这有可能吗?我试过这样:

function ReadZipEx(archivePath:String; outputPath:String; callback:longword): longword;
external 'ReadZipEx@ZipLib.dll stdcall';

并且喜欢这个

function ReadZipEx(archivePath:String; outputPath:String; callback:longword): longword;
external 'ReadZipEx@/subdir/ZipLib.dll stdcall';

但这只会导致错误。 我在sherlocksoftware的InnoCallback.dll的帮助下调用了库。

修改

正如TLama所设想的,我尝试了其他一些解决方案: 这将找到第一个dll而不是依赖。

function ReadZipEx(archivePath:String; outputPath:String; callback:longword): longword;
external 'ReadZipEx@{src}\ZipLib.dll stdcall loadwithalteredsearchpath';

这会导致错误:

function ReadZipEx(archivePath:String; outputPath:String; callback:longword): longword;
external 'ReadZipEx@{src}\ZipLib.dll,ICSharpCode.SharpZipLib.dll stdcall loadwithalteredsearchpath';

enter image description here

1 个答案:

答案 0 :(得分:1)

由于Inno Setup二进制文件从临时文件夹运行,因此您需要指定DLL库的路径。如果您希望将库保存在与安装二进制包相同的文件夹中,可以使用{src}常量扩展到那里:

[Code]
procedure DoSomething;
  external 'DoSomething@{src}\MyLib.dll stdcall';

如果您希望您的库在同一文件夹中搜索其依赖项(指定绝对路径时),您可以将loadwithalteredsearchpath选项添加到其导入定义中:

[Code]
procedure DoSomething;
  external 'DoSomething@{src}\MyLib.dll stdcall loadwithalteredsearchpath';

该参考将此选项描述为:

  

<强> loadwithalteredsearchpath

     

指定应使用Windows标志加载DLL   LOAD_WITH_ALTERED_SEARCH_PATH,实质上是导致加载器的   搜索包含DLL的目录中的任何依赖DLL。