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?
After you've loaded the resources dll with
LoadLibrary
, you store itsHMODULE
(returned byLoadLibrary
) and pass it to theLoadString
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 theLOAD_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).Are you loading the libray with LoadLibrary(Ex)? Remember the handle it returns.
Otherwise use GetModuleHandle("Name of resource module").
Use AfxGetResourceHandle().