-
May 30th, 2011, 09:12 PM
#1
[RESOLVED] Learn which language CString::LoadString() used
Hi everyone:
I was wondering, if I call CString::LoadString() method to load a string from resources how do I know which language did that method use?
-
May 30th, 2011, 10:14 PM
#2
Re: Learn which language CString::LoadString() used
Have you looked through the MFC sources to find out?
-
May 31st, 2011, 07:13 AM
#3
Re: Learn which language CString::LoadString() used
I don't understand the question.
-
May 31st, 2011, 07:32 AM
#4
Re: Learn which language CString::LoadString() used
Hi,
There's no obvious way to do it. You can specify the language you want to be used as the 3rd parameter. However, there's no way to check that MFC was actually able to find the string in that language in your resource DLL.
Alan
-
May 31st, 2011, 11:51 AM
#5
Re: Learn which language CString::LoadString() used
Originally Posted by alanjhd08
There's no obvious way to do it. You can specify the language you want to be used as the 3rd parameter.
CString::LoadString does not have any "3rd parameter". It has one and only one:
BOOL LoadString( UINT nID );
If the module (exe or dll) contains resources in more than one language then the only way to obtain the ones for the specific language rather than the default one is using resource APIs with Ex suffix:
FindResourceEx -> LoadResource -> LockResource
See How To Use LoadResource to Load Strings from a String Table
Victor Nijegorodov
-
May 31st, 2011, 03:41 PM
#6
Re: Learn which language CString::LoadString() used
Originally Posted by Arjay
Have you looked through the MFC sources to find out?
Yes. What happens on the inside is that the resource string is id'ed with a call to this Win32 API:
Code:
::FindResource( hInstance, MAKEINTRESOURCE( ((id>>4)+1) ), RT_STRING );
But that doesn't help me much.
Originally Posted by alanjhd08
There's no obvious way to do it
I agree, that seems to be the case.
Originally Posted by alanjhd08
You can specify the language you want to be used as the 3rd parameter. However, there's no way to check that MFC was actually able to find the string in that language in your resource DLL.
That is exactly the reason why I needed to know which version of a string resource was loaded. The reason being, in my application strings were processed a bit differently depending on the language.
Originally Posted by VictorN
CString::LoadString does not have any "3rd parameter". It has one and only one:
That is not true. Or at least in the last versions of MFC. There's also this method:
Originally Posted by msdn
BOOL LoadString(
HINSTANCE hInstance,
UINT nID,
WORD wLanguageID
);
But I would prefer not to use it and let the language be determined automatically. My reasoning behind it is that this whole language question is quite a complex subject that I may not completely understand at this stage (especially with custom locales in Vista, etc.) thus I'd prefer to let a Windows API handle the language selection.
But, fellas, I was able to find an easy workaround. By adding a simple language ID string into the resource (that is always in your predefined language, English, in my case) I can easily tell which language was actually loaded.
Code:
IDS_STRING_COUNTRY_ID "en_us"
-
May 31st, 2011, 04:10 PM
#7
Re: Learn which language CString::LoadString() used
Well, I cannot say I understand the solution.
Best regards,
Igor
-
May 31st, 2011, 04:22 PM
#8
Re: [RESOLVED] Learn which language CString::LoadString() used
Originally Posted by ahmd
But, fellas, I was able to find an easy workaround. By adding a simple language ID string into the resource (that is always in your predefined language, English, in my case) I can easily tell which language was actually loaded.
Code:
IDS_STRING_COUNTRY_ID "en_us"
Originally Posted by Igor Vartanov
Well, I cannot say I understand the solution.
I cannot it either...
Victor Nijegorodov
-
May 31st, 2011, 04:22 PM
#9
Re: Learn which language CString::LoadString() used
Originally Posted by Igor Vartanov
Well, I cannot say I understand the solution.
OK, say you have three string resources for English, French and German. You add the following string into each:
//For US resource
IDS_STRING_COUNTRY_ID "en_us"
//For French resource
IDS_STRING_COUNTRY_ID "fr_french"
//German resource
IDS_STRING_COUNTRY_ID "ge_german"
And then when the resource is loaded you check that ID to get the language of the resource loaded.
-
May 31st, 2011, 04:34 PM
#10
Re: Learn which language CString::LoadString() used
Could you demo the corresponding fragment from .rc file?
Best regards,
Igor
-
May 31st, 2011, 04:54 PM
#11
Re: Learn which language CString::LoadString() used
Originally Posted by Igor Vartanov
Could you demo the corresponding fragment from .rc file?
Igor, you're killing me.... Take a look at the resource file snippet:
Code:
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING_COUNTRY_ID "en_us"
IDS_STRING_HELLO_WORLD "Hello World!"
IDS_STRING_GOODBYE_WORLD "Goodbye World!"
END
/////////////////////////////////////////////////////////////////////////////
// French (France) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING_COUNTRY_ID "fr_france"
IDS_STRING_HELLO_WORLD "Bonjour tout le monde!"
IDS_STRING_GOODBYE_WORLD "Adieu le monde!"
END
#endif // French (France) resources
/////////////////////////////////////////////////////////////////////////////
// German (Germany) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
#ifdef _WIN32
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING_COUNTRY_ID "ge_german"
IDS_STRING_HELLO_WORLD "Hallo Welt!"
IDS_STRING_GOODBYE_WORLD "Goodbye Welt!"
END
#endif // German (Germany) resources
-
May 31st, 2011, 10:30 PM
#12
Re: Learn which language CString::LoadString() used
Thank you. You might be surprised, but I never did multilanguage support this way. It's always was a per-language resource dll.
Best regards,
Igor
-
June 1st, 2011, 12:38 PM
#13
Re: [RESOLVED] Learn which language CString::LoadString() used
The same applies to a resource DLL, doesn't it?
-
June 1st, 2011, 12:41 PM
#14
Re: [RESOLVED] Learn which language CString::LoadString() used
Originally Posted by ahmd
The same applies to a resource DLL, doesn't it?
What is "the same" in this context?
Victor Nijegorodov
-
June 1st, 2011, 12:45 PM
#15
Re: [RESOLVED] Learn which language CString::LoadString() used
Originally Posted by VictorN
What is "the same" in this context?
My approach.
How do you normally load your resource DLL, is it something explicit or you let an API decide which DLL to pick?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|