如何获取卫星资源DLL的模块句柄? (c ++ visual studio) [英] How do I get the module handle of the satellite resource DLL? (c++ visual studio )

查看:159
本文介绍了如何获取卫星资源DLL的模块句柄? (c ++ visual studio)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已将所有字符串移动到MFC应用程序的资源(和卫星DLL)。现在主语言被并入EXE本身,所以当我调用LoadString()我可以只传递exe的模块句柄。

We have moved all our strings to resources (and satellite DLLs) for an MFC application. Right now the primary language is incorporated into the EXE itself so when I call LoadString() I can just pass in the module handle of the exe.

然而,我需要使这个泛型 - 如何获得模块处理一个通用的方式,并确保我加载字符串形式的卫星DLL,如果适当?我们需要为当前加载的资源DLL获取适当的模块。 (或exe if英语)

However, I need to make this generic - how do I get the module handle in a generic way and make sure I load strings form a satellite DLL if appropriate? We need to get the appropriate module for the currently loaded resource DLL. (or the exe if English)

:: LoadString()方法接受一个句柄作为它的第一个参数 - 我们只是使用当前exe的句柄。

The ::LoadString() method takes a handle as its first argument - and we're just using the current exe's handle.

我必须确定是否需要加载DLL,否则Windows会自动为我执行此操作。从我读过的文档中不清楚。

Do I have to determine if I need to load the DLL, or does Windows automatically do that for me. It is not clear from the docs I have read.

这表示MFC会自动执行
如何获得该hmodule?

This indicates that MFC does it automatically. SO how do I get that hmodule?

推荐答案

c> LoadLibrary ,您存储其 HMODULE (由 LoadLibrary 返回),并将其传递 LoadString 函数(以及其他资源函数)。

After you've loaded the resources dll with LoadLibrary, you store its HMODULE (returned by LoadLibrary) and pass it to the LoadString function (as well as to the other resource functions).

顺便说一句,如果你使用资源DLL专门用于存储资源(即不包括任何代码),您可以使用 LOAD_LIBRARY_AS_DATAFILE 加载 LoadLibraryEx 选项,使加载更快一些,并避免由于嵌入在资源dll中的恶意代码的可能利用(但在这种情况下小心对话框)。

By the way, if you use your resources DLLs exclusively to store resources (i.e. no code is included in them) you can load them with LoadLibraryEx with the LOAD_LIBRARY_AS_DATAFILE option, making the loading a bit faster and avoiding possible exploits due to malicious code embedded in resources dlls (but in this case be careful with dialogs).

这篇关于如何获取卫星资源DLL的模块句柄? (c ++ visual studio)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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