Load a text ressource depending on selected language

Hello,

within my project (MFC) I load some strings from a text ressource. Depending on the selected language, I would like to load a different ressource file.
How can I select the correct ressourceID at runtime / or how can I check which language is set?

Best regards and thanks for your support,
Nils

Germany

Hi Nils

there are basically two options for handling resources in different languages:

  • compiling all resources into the main project
  • compiling the resources for each language into a separate, so called, satellite DLL


For MFC projects I strongly recommend using satellite DLLs.

To make the MFC classes use a satellite DLL, you must load it with the function LoadLibrary and then pass it to MFC by calling the function AfxSetResourceHandle()

This is the code I use in the "Select Language" dialog.

// Build a path for the satellite dll.
CString sSatellitePath = m_ApplicationDirectory + m_SelectedIetfTag + m_ApplicationName + "_" + m_SelectedIetfTag + ".dll" ;

// Does this file exist?
WIN32_FIND_DATA WFD ;
if ( FindFirstFile ( sSatellitePath, &WFD ) != INVALID_HANDLE_VALUE )
{
  HMODULE   hDLL = LoadLibrary ( sSatellitePath ) ;
  if ( hDLL )
  {
    AfxSetResourceHandle ( hDLL ) ;
  }
}


To load a single resource string, the easiest way is to define a CString variable and to use the LoadString member function.

Phil