How do I get the module handle of the satellite resource DLL? (c++ visual studio )

寵の児 提交于 2020-01-04 03:18:04

问题


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.

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)

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

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.

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


回答1:


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).

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).




回答2:


Are you loading the libray with LoadLibrary(Ex)? Remember the handle it returns.

Otherwise use GetModuleHandle("Name of resource module").




回答3:


Use AfxGetResourceHandle().



来源:https://stackoverflow.com/questions/5340312/how-do-i-get-the-module-handle-of-the-satellite-resource-dll-c-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!