tags:

views:

414

answers:

1

I am talking about win32 dlls, those plain pe files. I am confused after I doing a test compared to what I saw in explorer.exe process.

  1. I wrote a test with following modules:(C++)
    DLLLoader.exe links to A.dll in the same folder.
    B.dll links to A.dll(2) in another folder. (A.dll(2) is a totally different DLL from A.dll, but with the same name)
    DLLLoader.exe will load B.dll explicitly through ::LoadLibrary.
    Now I start DllLoader.exe, firstly, A.dll will be loaded, but then when it tries to load B.dll, It just failed: I suspect that is because B.dll thinks A.dll is already loaded in process, but in fact, the loaded one is not the one B.dll wanted, the import/export table can't match, so B.dll is failed to load.
    This seems to tell us we can't loaded 2 dlls of same name in the same process, even they are of different path.

  2. But when I used process explorer to monitor loaded modules in Windows's explorer.exe process, I could see following 2 dlls being loaded, with same name:
    comctl32.dll User Experience Controls Library C:\WINDOWS\WinSxS...\comctl32.dll
    comctl32.dll Common Controls Library C:\WINDOWS\system32\comctl32.dll

Could any of you shed some lights on this?

+1  A: 

It basically depens on if you load the dll with its full path or only by file name. The LoadLibraryEx docs cover this pretty well:

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

Mattias S
So as to impilict loading (based on DLL dependency), we could only have 1 dll loaded with the same name.
lz_prgmr