Inno Setup:将DLL放在子目录中 [英] Inno Setup: Put DLLs in a subdirectory

查看:143
本文介绍了Inno Setup:将DLL放在子目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将依赖项(几个DLL文件)复制到一个单独的子目录中。安装程序后,目录结构如下:

I want to have the dependencies (a couple of DLL files) copied in a separated sub directory. After installing my program, the directory structure would look like:


  • dlls /


    • a.dll

    • b.dll

    我脚本的相关部分如下:

    The relevant part of my script is as follows:

    [Dirs]
    Name: "{app}\sample"
    Name: "{app}\dll"
    [Files]
    Source: "pg.exe"; DestDir: "{app}"; Flags: ignoreversion
    ; icon file
    ;Source: "pg.ico"; DestDir: "{app}"
    ; sample ini and geoemtry file
    Source: "geometry.xml"; DestDir: "{app}\sample"
    Source: "ini.xml"; DestDir: "{app}\sample"
    
    ; DLL  
    Source: "a.DLL"; DestDir: "{app}\dll"; Flags: onlyifdoesntexist 
    Source: "b.DLL"; DestDir: "{app}\dll"; Flags: onlyifdoesntexist 
    

    当我在VM中测试安装程序时,出现错误,提示a.DLL是未找到。如果我仅将 a.DLL dll / 复制到可执行文件的目录,就可以快速解决该问题。

    When I test my installer in a VM I get an error saying that a.DLL is not found. The problem is quickly solved if I just copy a.DLL from dll/ to the directory of the executable.


    • 是否有必要将所有dll与可执行文件置于同一级别?

    • 或者是否有办法使可执行文件在子目录dll /中找到其依赖项?

    推荐答案

    如果使用隐式DLL链接,则只有几个目录
    可在其中放置必要的DLL文件。假设 SafeDllSearchMode 处于打开状态(这是Window XP SP2以来的默认设置),Windows加载程序将按以下顺序搜索DLL:

    If you are using implicit DLL linkage, then there are only several directories where you can place the necessary DLL files. Assuming SafeDllSearchMode is on (which is the default since Window XP SP2), Windows loader searches DLLs in this order:


    1. 可执行文件所在的目录

    2. Windows目录

    3. Windows系统目录

    4. 当前工作目录

    5. PATH环境变量中列出的目录

    1. The directory where your executable located
    2. The Windows directory
    3. The Windows system directory
    4. The current working directory
    5. The directories listed in the PATH environment variable

    有关搜索顺序的更多信息,请参见 https ://msdn.microsoft.com/zh-CN/library/windows/desktop/ms682586(v = vs.85).aspx

    For more information about search order see https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

    如果使用这种类型的链接时,建议您将DLL与可执行文件放在
    相同的目录中。

    If you are using this type of linkage, I would suggest you place your DLLs in the same directory as your executable.

    另一方面,如果您显式使用 LoadLibrary
    LoadLibraryEx API链接到这些DLL,这是您可以做的:

    On the other hand, if you are explicitly linking to these DLL using LoadLibrary or LoadLibraryEx APIs, here is what you can do:


    1. 您可以调用 AddDllDirectory 并将路径传递给包含
      DLL的目录。确保在加载库之前调用此函数,并确保使用标记为 LOAD_LIBRARY_SEARCH_USER_DIRS LoadLibraryEx 来加载
      。 c $ c>。

    2. 您可以使用 GetModuleFileName 函数检索可执行文件的路径,然后
      使用它来构造DLL的绝对路径,并在调用 LoadLibrary(Ex)时使用这些路径。

    3. 您可以调用 SetDllDirectory ,然后调用 LoadLibrary(Ex)。此
      方法的问题在于,每次调用 SetDllDirectory 函数时,它将替换上一个中指定的目录
      。 SetDllDirectory
      调用。如果您不小心
      ,这可能会导致问题,因为代码的其他部分可能会调用 SetDllDirectory 并在加载DLL时导致失败

    1. You can call AddDllDirectory and pass it the path to directory that contains your DLLs. Make sure you call this function before you load the libraries, and make sure you load the libraries using LoadLibraryEx with flag LOAD_LIBRARY_SEARCH_USER_DIRS.
    2. You can retrieve the path to your executable using GetModuleFileName function, then use it to construct absolute paths to DLLs and use these paths when calling LoadLibrary(Ex).
    3. You can call SetDllDirectory before calling LoadLibrary(Ex). The problem with this method is that each time the SetDllDirectory function is called, it replaces the directory specified in the previous SetDllDirectory call. This can cause problems if you are not careful because some other part of code could call SetDllDirectory and cause failure when loading your DLLs

    这篇关于Inno Setup:将DLL放在子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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