Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LoadResString() and different languages...

0 views
Skip to first unread message

Kai Hietala

unread,
Sep 7, 2001, 6:27:03 AM9/7/01
to
Hi,

I have been using the language resource in VB. Is there a way to
influence what language the LoadResString() function returns?

I experimented some time ago and found out that SetThreadLocale()
changed the language returned by that function. As I recall it wasn't
100% guaranteed to work and for some reason it doesn't behave the same
on W2000. On W2000 the language doesn't change. :-(

Example: My user / system settings are set for Finnish but I'd like to
use the Swedish language section of the .res file...

Thanks,

-Kai

Michael (michka) Kaplan

unread,
Sep 7, 2001, 10:46:21 AM9/7/01
to
Sorry, but LoadResString is not your choice here, there is no reliable way
to influence it. You have two choices:

1) Split your language resources into separate satellite DLLs, one per
language.

2) use the much tougher resource functions to load raw resources.

Of the two, #1 is more scalable, a better practice in terms of the best way
to handle localization, and a LOT more VB-friendly.

--
MichKa

the only book on internationalization in VB at
http://www.i18nWithVB.com/

"Kai Hietala" <Kai.H...@predisys.com> wrote in message
news:3B98A0F7...@predisys.com...

Richard Jalbert

unread,
Sep 7, 2001, 12:49:38 PM9/7/01
to
We made it like this:

In the RES file, we add another string table and set the language of
it: we used German (the first one is always English by default.)

When you install and run you program, the string load will be in that
language if you have a string table that refers to it. Else it will be
in English.

=====================================================
Did you know my cats can type by sitting *on* my
keyboard?
rich...@sympatico.ca.No.Spam
http://www3.sympatico.ca/richmann/
http://www.geocities.com/richmannsoft/index.html
=====================================================

Hakan Ornek

unread,
Sep 8, 2001, 4:35:42 AM9/8/01
to
Hi Kai,
Try this code with FindResourceEx;
'---------------------------------------------------------------------------
------------------------------
int LoadStringEx(HINSTANCE hInstance, UINT uID, WORD wLanguage, LPTSTR
lpBuffer, int nBufferMax )
{
HGLOBAL hGlb=NULL;
LPWSTR lpwsz=NULL;
LPVOID lpMsgBuf=NULL;
ULONG lSize(0);
HRSRC hRsrc = FindResourceEx(hInstance, RT_STRING,
MAKEINTRESOURCE((uID>>4)+1) , wLanguage);
if (!hRsrc ) {
lpMsgBuf=NULL;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
NULL
// Display the string.
::MessageBox(NULL, static_cast<LPTSTR>(lpMsgBuf), "Error", MB_OK |
MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
return 0;
}
hGlb = LoadResource(NULL, hRsrc);
lpwsz = static_cast<LPWSTR>(LockResource(hGlb));
file://increment the pointer in the resource block up to the required
string
for(UINT i(0),nStrLen(0);i<(uID & 15);i++,nStrLen=lpwsz++[0]) {
lpwsz+=nStrLen; file://jump over preceding resources in the block
}
size_t nRet = wcstombs(lpBuffer, lpwsz, min(nStrLen,(size_t)
nBufferMax));
lpBuffer[nRet]='\0';
return nRet;
}

'---------------------------------------------------------------------------
------------------------------
I hope it's works.

Hakan Ornek


"Kai Hietala" <Kai.H...@predisys.com> wrote in message
news:3B98A0F7...@predisys.com...

Michael (michka) Kaplan

unread,
Sep 8, 2001, 6:14:33 AM9/8/01
to
(And of course convert the code to something a bit more VB-friendly? <g>)

--
MichKa

Michael Kaplan
Trigeminal Software, Inc.
http://www.trigeminal.com/
(principal developer of the MSLU)

"Hakan Ornek" <ha...@prohakedis.com> wrote in message
news:u#Ih#tDOBHA.1812@tkmsftngp04...

0 new messages