This content has moved to another location. See GetLocaleInfo for the latest version.
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
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.
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...
This snippet will get the English name of the current user's default language:
LCID lcidLocaleId; // locale identifierLCTYPE lctyLocaleInfo; // information typePWSTR pstr; // information bufferINT 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 }}
With reference to CALID used in the code fragment in this article as such:
int ret;
DWORD valueCALID 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;