Click to Rate and Give Feedback
MSDN
MSDN Library

  Switch on low bandwidth view
GetLocaleInfo

This content has moved to another location. See GetLocaleInfo for the latest version.

Community Content   What is Community Content?
Add new content RSS  Annotations
LOCALE_NOUSEROVERRIDE should be avoided      Shawn Steele [MSFT]   |   Edit   |   Show History

LOCALE_NOUSEROVERRIDE should be avoided

Users specify overrides for a reason :), and expect them to be used. If your app needs a specific format, it should pass in a format instead of depending on the locale data. (See "Culture data shouldn't be considered stable (except for Invariant)" http://blogs.msdn.com/shawnste/archive/2005/04/05/405694.aspx

Tags What's this?: Add a tag
Flag as ContentBug
GetLocaleInfoEx is preferred      Shawn Steele [MSFT]   |   Edit   |   Show History

GetLocaleInfoEx is preferred

Try to avoid LCIDs and use locale names if possible

Users can create custom locales which your application may not have access to if it doesn't use the locale name. Custom locales don't get their own LCIDs, so functionality is limited if your application relies on the LCID. See this blog http://blogs.msdn.com/shawnste/pages/custom-cultures-vista-custom-locales.aspx for more info about locales/custom locales and good behavior with locales.

Tags What's this?: Add a tag
Flag as ContentBug
GetLocalInfoEx is Vista and later only...      Red!   |   Edit   |   Show History

I wanted to use GetLocaleInfoEx... until I realized It's Vista+ only... I would use it if the app was only used on that target system but for simplicitie's sake I won't code a wrapper nor compile a special runtime just to support Ex on Vista...

Tags What's this?: Add a tag
Flag as ContentBug
Sample usage of GetLocaleInfo()      ddaS-edEn   |   Edit   |   Show History

This snippet will get the English name of the current user's default language:

LCID lcidLocaleId;     // locale identifier
LCTYPE lctyLocaleInfo; // information type
PWSTR pstr; // information buffer
INT iBuffSize; // size of buffer
lcidLocaleId = LOCALE_USER_DEFAULT;
lctyLocaleInfo = LOCALE_SENGLANGUAGE /*0x00001001*/;
// Determine the size of the buffer needed to retrieve information.
iBuffSize = GetLocaleInfo( lcidLocaleId, lctyLocaleInfo, NULL, 0 );
if(iBuffSize > 0)
{
// Allocate the buffer for the locale info string
pstr = (WCHAR *) malloc( iBuffSize * sizeof(WCHAR) );
if(pstr != NULL)
{
if(GetLocaleInfoW( lcidLocaleId, lctyLocaleInfo, pstr, iBuffSize ))
{
MessageBox(pstr);
}
free(pstr); //free locale info string
}
}

CALID - Calendar ID is DWORD      ddaS-edEn ... Shawn Steele [MSFT]   |   Edit   |   Show History

With reference to CALID used in the code fragment in this article as such:

int ret;
DWORD value
CALID calid;
ret = GetLocaleInfoW( LOCALE_USER_DEFAULT,
LOCALE_ICALENDARTYPE | LOCALE_RETURN_NUMBER,
(LPWSTR)&value;,
sizeof(value) / sizeof(WCHAR) );
calid = value;

Note that LOCALE_RETURN_NUMBER is expecting a DWORD to be returned, so strictly you probably shouldn't pass in a CALID, except it happens to be a DWORD so it works.

The length that GetLocaleInfo() expects is in terms of the string, so sizeof(TCHAR) is correct, although I'd prefer use of the W version and WCHAR explicitly.


CALID is defined in WinNls.h as such:

//
// Calendar ID.
//
typedef DWORD CALID;

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker