一个进程可以加载两个名称完全相同的 DLL 吗?
Can a process load two DLLs with exactly the same name?
帮忙翻译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
中? And where/how 是否有文档记录和支持(否则我会尝试一下。)
也就是说,以下内容是否可以在 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.
因此,当提供完整路径时,您担心的条款不适用。
帮忙翻译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
中? And where/how 是否有文档记录和支持(否则我会尝试一下。)
也就是说,以下内容是否可以在 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.
因此,当提供完整路径时,您担心的条款不适用。