herzbube
herzbube

Reputation: 13378

How does MFC determine the default language ID when loading resources?

I have an MFC project that contains one .rc file for US English, and one .rc file for Swiss German. The two .rc files are identical except for 1) a single string that I am using for my tests, and 2) the .rc files use different LANGUAGE statements at the top:

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US    >>> for US English
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN_SWISS   >>> for Swiss German

I am including the two .rc files from a single main .rc file. The main .rc file is compiled, the language-specific .rc files are set to "exclude from build".

I believe I have setup everything correctly, because I can use a snippet like the following to successfully load a string resource from the Swiss German language resource file:

WORD swissGermanLanguageID =
    MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS);
WORD swissGermanLCID =
    MAKELCID(swissGermanLanguageID, SORT_DEFAULT);
CString teststring;
teststring.LoadString(AfxGetResourceHandle(), IDS_TESTSTRING, swissGermanLCID);

The problem is: When I omit the language ID, such as in the following snippet, MFC always loads the resource from the US English resources, no matter what I try:

CString teststring;
teststring.LoadString(IDS_TESTSTRING);

Things that I have tried/checked:

OK, so finally, here's the question: How does MFC determine the default language ID that it uses when it loads resources? And even better: How can I change that default language ID?


Here's the snippet I mentioned above that I'm using to set the thread locale:

WORD swissGermanLanguageID =
    MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS);
WORD swissGermanLCID =
    MAKELCID(swissGermanLanguageID, SORT_DEFAULT);
SetThreadLocale(swissGermanLCID);

Upvotes: 4

Views: 2162

Answers (1)

user7860670
user7860670

Reputation: 37550

  • Please check which resources are actually packed into your executable. You can use something like Explorer's Suite or other resource editor.
  • On Windows Vista and newer resource loading order is determined by the list of preferred languages that you can obtain using GetThreadPreferredUILanguages family of functions (there are a separate list for user, for process and for thread that get combined to perform resource lookup). Potentially it may be altered by MFC runtime, but I'm not sure about it. On your system this list will probably contain 4 entries: [de-CH, de, en-US, en].
  • Splitting resources into separate mui dlls might be a good idea, though it should work perfectly fine when everything is packed into a single executable.

Upvotes: 2

Related Questions