Discussion:
SDK integration in VS2005
(too old to reply)
Hans-J. Ude
2007-11-06 14:10:37 UTC
Permalink
In my MFC application I have resources in german as default and in english,
all included in the .exe. Whenever the program runs under a german version
of the OS it appears in german if it runs on any other language it should
come up in english. I'm using this code:

#ifdef FORCE_ENGLISH_US
lcidUser =
MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
#else
lcidUser = GetUserDefaultLCID();
#endif
LANGID langid = LANGIDFROMLCID(lcidUser);
if (PRIMARYLANGID(langid) != LANG_GERMAN)
{
LCID lcidUsEnglish =
MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
SetThreadLocale (lcidUsEnglish);
// SetThreadUILanguage(lcidUsEnglish);
}

That worked with XP but in Vista they seem to have changed the
implementation of SetThreadLocale() because it doesn't work any more. So I
tried to use SetThreadUILanguage() instead. Now comes the problem. That
function is undefined. I've read somewhere that it requires an appropriate
SDK to be installed and I downloaded and installed the Vista SDK. There is a
tool called "Visual Studio 2005 integration tool". When I run it, I get the
message "Unable to access the required files. Login as administrator and try
rerunning the tool". I am an administrator so I'm wondering what's going
wrong here.

TIA,
Hans
Christoph Conrad
2007-11-06 14:33:17 UTC
Permalink
Hi Hans-Jürgen,
So I tried to use SetThreadUILanguage() instead. Now comes the
problem. That function is undefined.
I choosed another way, see below. Unfortunately SetThreadLocale does not
always work. On one computer it works for me for one user, but not for
another user. MSDN says that it is not recommended, one should use other
ways like FindResourceEx (a lot of changes), or satellite language dlls.

///////////////////////////////////////////////////////////////////////
// \author Christoph Conrad
// \date 05.11.2007
// \note Check if OS is vista or newer
// \return true if OS is vista or newer
///////////////////////////////////////////////////////////////////////
bool IsVistaOrNewer()
{
OSVERSIONINFO OSversion;
OSversion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&OSversion);

// check for vista or newer
return OSversion.dwMajorVersion >= 6;
}


///////////////////////////////////////////////////////////////////////
// \author Christoph Conrad
// \date 05.11.2007
// \note Switch program language
// \param the language identifier, e.g. LANG_GERMAN ("winnt.h")
// \return true if switching worked
///////////////////////////////////////////////////////////////////////
bool SwitchLanguage(USHORT primaryLanguage)
{
LANGID langId = MAKELANGID(primaryLanguage, SUBLANG_DEFAULT);
bool success = false;

// check for vista or newer

// In Windows XP SetThreadUILanguage() also exists, but the parameter is
// ignored. So we must check if it is vista.
if( IsVistaOrNewer() )
{
// Hole Handle fuer die DLL.
HMODULE dllHandle = LoadLibrary("kernel32");
success = dllHandle != NULL;
// Wenn Handle gueltig, ermittle Adresse der Funktion.
if( success )
{
typedef short (CALLBACK* SetThreadUILanguageType)(LANGID);
SetThreadUILanguageType stuiPtr = (SetThreadUILanguageType)
GetProcAddress(dllHandle, "SetThreadUILanguage");

success = stuiPtr && stuiPtr(langId) != 0;

// Aufraeumen
FreeLibrary(dllHandle);
}
}

// fallback, try SetThreadLocale()
if( ! success )
{
success =
::SetThreadLocale( MAKELCID(langId, SORT_DEFAULT ) ) != 0;
}

return success;
}

Best regards,
Christoph
Christoph Conrad
2007-11-06 14:40:20 UTC
Permalink
[SetThreadLocale]
All i said applies to Windows 2000 or Windows XP. On Windows Vista you
should use SetThreadUILanguage, as the code does.
Hans-J. Ude
2007-11-06 14:54:10 UTC
Permalink
Post by Christoph Conrad
[SetThreadLocale]
All i said applies to Windows 2000 or Windows XP. On Windows Vista you
should use SetThreadUILanguage, as the code does.
That's what I wanted to do. But this is the point where the SDK
installation problem shows up.

Hans
Christoph Conrad
2007-11-06 15:00:46 UTC
Permalink
Hallo Hans-J,
Post by Hans-J. Ude
That's what I wanted to do. But this is the point where the SDK
installation problem shows up.
I had the same problem. My code handles this by dynamically getting the
address of SetThreadUILanguage at runtime. But beware:
SetThreadUILanguage is also existent on Windows XP, but does ignore the
language id parameter - have a look at the code i posted!

Freundliche Grüße,
Christoph

Loading...