windows - 一个进程可以加载两个名称完全相同的 DLL 吗?

标签 windows winapi visual-c++ dll loadlibrary

帮助翻译MSDN :

Dynamic-Link Library Search Order

...

If a DLL with the same module name is already loaded in memory, the system checks only for redirection and a manifest before resolving to the loaded DLL, no matter which directory it is in. The system does not search for the DLL.

注意:具有相同名称的多个 DLL 基本上一个坏主意,这只是为了获得更好的画面。

考虑:

...\x\foo.exe
...\x\a\bar.dll ~ no further dependencies
...\x\b\bar.dll ~ no further dependencies

是否可以通过显式加载库调用将这两个 bar.dll 加载到 foo.exe 中? 这是在哪里/如何记录和支持的(否则我会尝试一下。)

也就是说,以下是否可以在 Windows7+ 上可靠地工作:

// Load using full path:
HANDLE a_mod = LoadLibrary(L"...\x\a\bar.dll");
HANDLE b_mod = LoadLibrary(L"...\x\b\bar.dll");
// now use moth DLLs ...

最佳答案

来自文档(强调我的):

Desktop applications can control the location from which a DLL is loaded by specifying a full path, using DLL redirection, or by using a manifest. If none of these methods are used, the system searches for the DLL at load time as described in this section.

Before the system searches for a DLL, it checks the following:

  • If a DLL with the same module name is already loaded in memory, the system uses the loaded DLL, no matter which directory it is in. The system does not search for the DLL.

因此,当提供完整路径时,您担心的子句不适用。

关于windows - 一个进程可以加载两个名称完全相同的 DLL 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43217552/

相关文章:

windows - 浏览器无法识别虚拟驱动摄像头

c++ - 从 C++ 调用 lib 文件中的 c 函数

windows - 用于打开多个 CMD 窗口的批处理脚本的奇怪行为

c# - 使用C#隐藏任务栏

windows - 是否可以将非控制台 Win32 应用程序附加到调用 cmd shell?

c++ - 当我使用 SendInput 发送鼠标光标位置时屏幕变黑

c++ - 新对象中的空函数指针实际上不是 nullptr

visual-c++ - 为什么在 WIN8 下使用 Touch Injection API 时只能注入(inject)一次触摸?

c++ - 链式ostream内部行为及其在MSVC上的结果(与Clang相比)

c++ - 如何简化我的 C++ 代码以反转字符?