COMCTL32.DLL 加载两次时的 GetModuleHandle 和 GetProcAddress

发布于 2024-12-02 17:07:51 字数 480 浏览 1 评论 0原文

我正在一个进程中运行,其中 COMCTL32.DLL 被加载两次,一次使用版本 5.82.7601.17514,一次使用版本 6.10.7601.17514。旧版本由程序链接的某个旧 DLL 加载,另一个版本由较新的 DLL 加载。

如果我使用 GetModuleHandle (L"COMCTL32.DLL") ,我无法控制解析的 DLL。

例如,当我调用 GetProcAddress 来访问 TaskDialogIndirect 时,我得到了一个空指针,这肯定是因为我得到了旧 DLL 的句柄。

那么,当两个 DLL 都加载时,是否有某种方法可以获取例如 TaskDialogIndirect 的地址。

如果没有,我能否以某种方式确保该进程加载 6.10 版本而不是 5.82,希望我们的旧版 DLL 能够与新版本的 COMCTL32 正常工作?

I am running inside a process where COMCTL32.DLL is loaded twice, once with the version 5.82.7601.17514 and once with the version 6.10.7601.17514. The legacy version is loaded by some legacy DLL the program is linked with, and the other version is loaded by a newer DLL.

If I use GetModuleHandle (L"COMCTL32.DLL") I have no control over the DLL which gets resolved.

When I call GetProcAddress to reach, for instance, TaskDialogIndirect, I get a null pointer back, which is certainly because I got back the handle of the legacy DLL.

So, is there some means of getting to the address of, say TaskDialogIndirect when both DLLs are loaded.

If not, can I somehow make sure that the process loads the 6.10 version and not the 5.82, in the hope that our legacy DLL will work fine with the newer version of COMCTL32?

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

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

发布评论

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

评论(1

甜点 2024-12-09 17:07:51

我猜您必须使用 GetProcAddress() 而不是隐式链接,因为您希望您的应用程序在任务对话框不可用的 XP 上运行。

我可以为您提供三个选项:

  1. 使用隐式链接,但使用 MS 工具链支持的延迟加载。我不能 100% 确定会给你正确的 comctl32 但值得一试。
  2. 使用激活上下文 API确保在调用 LoadLibrary() 时 comctl32 v6 清单正在运行。调用 LoadLibrary() 而不是 GetModuleHandle() 以确保您获得了明显的魔力。
  3. 枚举进程中的所有模块并选择正确的comctl32版本。 MSDN 上有一个 如何执行此操作的综合示例< /a>.

激活上下文方法是最简洁的解决方案,但激活上下文 API 可能很难使用。我个人用它来确保 Excel COM 加载项链接到 comctl32 v6。

模块枚举方法实现起来很快,虽然有点脏,但效果很好。

I guess you are having to use GetProcAddress() rather than implicit linking because you want your app to run on XP where task dialog is not available.

I can see three options for you:

  1. Use implicit linking, but use delay loading as supported by the MS tool chain. I'm not 100% certain that will give you the correct comctl32 but it's worth a try.
  2. Use the activation context API to make sure that the comctl32 v6 manifest is in play when you call LoadLibrary(). Call LoadLibrary() rather than GetModuleHandle() to make sure that you get the manifest magic.
  3. Enumerate all the modules in the process and select the correct version of comctl32. There is a comprehensive example of how to do this on MSDN.

The activation context approach is the cleanest solution, but the activation context API can be tricky to get into. I personally have used it to ensure that an Excel COM add-in links to comctl32 v6.

The module enumeration approach is quick to implement, somewhat dirty, but will work well.

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