我们可以在一个进程中加载​​ 2 个同名的 DLL吗?

发布于 2024-08-03 07:01:00 字数 681 浏览 1 评论 0原文

我说的是 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 的 explorer.exe 进程中加载​​的模块时,我可以看到以下 2 个 dll 正在加载,且名称相同:
    comctl32.dll 用户体验控制库 C:\WINDOWS\WinSxS...\comctl32.dll
    comctl32.dll 通用控件库 C:\WINDOWS\system32\comctl32.dll

你们中有人能解释一下吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哭了丶谁疼 2024-08-10 07:01:00

它基本上取决于您是否使用完整路径或仅通过文件名加载 dll。 LoadLibraryEx 文档很好地介绍了这一点:

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

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.

夏末的微笑 2024-08-10 07:01:00

请参阅 http://social .msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b3eaa07f-7f92-4693-8aa1-b8fee0b92d2f/ 很好地讨论了如何通过激活上下文为 WinXP 及更高版本隐式完成此操作(清单)来控制加载。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文