我们可以在一个进程中加载​​相同名称的2个DLL [英] Could we have 2 DLLs with the same name being loaded in one process

查看:265
本文介绍了我们可以在一个进程中加载​​相同名称的2个DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在谈论win32 dll,那些简单的pe文件。我在进行测试后感到困惑,与我在explorer.exe进程中看到的相比。


  1. 我写了一个跟随测试模块:(C ++)

    DLLLoader.exe链接到同一文件夹中的A.dll。

    B.dll链接到另一个文件夹中的A.dll(2)。 (A.dll(2)是一个与A.dll完全不同的DLL,但名称相同)

    DLLLoader.exe将通过:: LoadLibrary显式加载B.dll。

    现在我启动DllLoader.exe,首先,A.dll将被加载,但是当它尝试加载B.dll时,它刚刚失败:我怀疑是因为B.dll认为A.dll已经加载进程,但实际上,加载的不是一个B.dll想要的,导入/导出表不能匹配,所以B.dll无法加载。

    这似乎告诉我们,我们可以'在同一个进程中加载​​了相同名称的两个dll,即使他们有不同的路径。


  2. 但是当我使用进程浏览器监视Windows的浏览器中加载的模块.exe进程,我可以看到以下2个dll被加载,同名:

    comctl32.dll用户体验控件库C:\WINDOWS\WinSxS ... \comctl32.dll

    comctl32.dll公共控件库C:\WINDOWS\system32\comctl32.dll


你们中有人可以点亮这个吗?

解决方案

它基本上取决于如果您使用其完整路径或只通过文件名加载dll。 LoadLibraryEx 文档涵盖这一点:


如果lpFileName不包含路径
,并且有多个加载的
模块具有相同的基本名称和
扩展名,该函数返回一个
句柄到已加载
的模块。



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?

解决方案

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.

这篇关于我们可以在一个进程中加载​​相同名称的2个DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆