Windows 上的 DLL 搜索 [英] DLL search on windows

查看:14
本文介绍了Windows 上的 DLL 搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 linux 上,我们有 LIBRARY_PATHLD_LIBRARY_PATH 环境变量,以便程序搜索库.我们在windows上有类似的东西吗?特别是Windows 7?

On linux, we have LIBRARY_PATH and LD_LIBRARY_PATH environment variables in order for programs to search for libraries. Do we have similar thing on windows? Particularly Windows 7?

此外,我想知道 DLL 使用的最佳实践(将它们放在哪里,是否使用 envs 等),因为我想像每个人一样在 Windows 上工作,而不是在解决方法上懒惰:)

Also, I would like to know best practices for DLL use (where to put them, use envs or not, etc.), since I want to work on windows like everyone does, and not to sloth myself on workarounds :)

推荐答案

正如 Bob 所解释的,这个答案描述了替代搜索顺序,这不是大多数应用程序会看到的.完整的规则非常复杂.我不认为我可以在这里总结它们.相反,请阅读 Microsoft 文档 - https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order

As explained by Bob, this answer describes the Alternate Search Order, which is not what most applications would see. The full rules are quite complex. I don't think I can summarize them here. Instead, read the Microsoft docs - https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order

我最初的回答是:

这篇 MSDN 文章解释默认搜索顺序.我引用:

This MSDN article explains the default search order. I quote:

  1. lpFileName 指定的目录.
  2. 系统目录.使用 GetSystemDirectory 函数获取该目录的路径.
  3. 16 位系统目录.没有获取这个目录路径的函数,但是会搜索.
  4. Windows 目录.使用 GetWindowsDirectory 函数获取该目录的路径.
  5. 当前目录.
  6. 在 PATH 环境变量中列出的目录.请注意,这不包括 App Paths 注册表项指定的每个应用程序路径.计算 DLL 搜索路径时不使用 App Paths 键.

在(1)中,如果你静态链接到DLL的存根库,我认为lpFileName指定的目录"是进程的exe路径.

In (1), if you statically linked against the DLL's stub library, I think "the directory specified by lpFileName" is the process's exe's path.

这篇关于Windows 上的 DLL 搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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