Help interpreting 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.
Note: Multiple DLLs with the same name basically is a bad idea, this is just to get a better picture.
Consider:
...\x\foo.exe
...\x\a\bar.dll ~ no further dependencies
...\x\b\bar.dll ~ no further dependencies
Is it possible to load both of these bar.dll
into foo.exe
with explicit load library calls? And where/how is this documented and supported (otherwise I'd just try it.)
That is, will the following reliably work on 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 ...
You can not load the same DLL multiple times into a single process (or not and have any effect). If you make the DLL a COM host and use COM objects then this will be automatically handled by each class instance.
Every process that loads the DLL maps it into its virtual address space. After the process loads the DLL into its virtual address, it can call the exported DLL functions. The system maintains a per-process reference count for each DLL. When a thread loads the DLL, the reference count is incremented by one.
Threads in DllMain hold the loader lock so no additional DLLs can be dynamically loaded or initialized. The entry-point function should perform only simple initialization or termination tasks.
DLLs, or dynamic link libraries, are like the building blocks of Windows. Shared DLLs are basically DLL files that are shared between many different apps. Additionally, there are many common DLLs that are used by most, if not all, Windows applications.
From the documentation (emphasis mine):
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.
So, the clause you're worried about doesn't apply when a full path is provided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With