Can we have 2 DLLs with the same name loaded in one process

I am talking about win32 dll, these simple pe files. I am confused after I run the test, compared to what I saw in the process explorer.exe.

  • I wrote a test with the following modules: (C ++)
    DLLLoader.exe refers to A.dll in the same folder.
    B.dll refers to A.dll (2) in another folder. (A.dll (2) is a completely different DLL from A.dll, but with the same name)
    DLLLoader.exe will load B.dll explicitly through :: LoadLibrary.
    Now I run DllLoader.exe, firstly, A.dll will be loaded, but then when it tries to load B.dll, it just does not work: I suspect that this is because B.dll considers A.dll already loaded in the process, but in fact, the one loaded is not the one required by B.dll, the import / export table cannot match, therefore B.dll does not load.
    This apparently tells us that we cannot load 2 DLLs with the same name in the same process, even if they have a different path.

  • But when I used the process handler to monitor the loaded modules during Windows explorer.exe, I could see how 2 DLLs with the same name are loaded:
    comctl32.dll User Control Panel C: \ WINDOWS \ WinSxS ... \ comctl32.dll
    comctl32.dll Common Controls Library C: \ WINDOWS \ system32 \ comctl32.dll

Can any of you shed light on this?

+7
process dll
source share
2 answers

This mainly depends on whether the dll load your full path or just by file name. LoadLibraryEx docs talk quite well about this:

If lpFileName does not contain a path and there is more than one loaded module with the same base name and extension, the function returns to access the loaded module first.

+6
source share

See http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b3eaa07f-7f92-4693-8aa1-b8fee0b92d2f/ for a good discussion of how this can be done implicitly for WinXP and up, through activation context (manifest) to control the download.

+5
source share

All Articles