Converts a locale name to a locale identifier.
Note For custom locales, including those created by Microsoft, your applications should prefer locale names over locale identifiers.
Syntax
LCID LocaleNameToLCID( __in LPCWSTR lpName, __in DWORD dwFlags );
Parameters
- lpName [in]
-
Pointer to a null-terminated string representing a locale name, or one of the following predefined values.
- dwFlags [in]
-
Prior to Windows 7: Reserved; should always be 0.
Windows 7 and later: Can be set to LOCALE_ALLOW_NEUTRAL_NAMES to allow the return of a neutral LCID.
Return value
Returns the locale identifier corresponding to the locale name if successful. If the supplied locale name corresponds to a custom locale that is the user default, this function returns LOCALE_CUSTOM_DEFAULT. If the locale name corresponds to a custom locale that is not the user default, the function returns LOCALE_CUSTOM_UNSPECIFIED.
The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:
- ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.
Examples
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
int _cdecl main(
int argc,
char *argv[])
{
WCHAR strNameBuffer[LOCALE_NAME_MAX_LENGTH];
DWORD error = ERROR_SUCCESS;
LCID lcid;
// Get the name for locale 0x10407 (German (German), with phonebook sort)
if (LCIDToLocaleName(0x10407, strNameBuffer, LOCALE_NAME_MAX_LENGTH, 0) == 0)
{
// There was an error
error = GetLastError();
}
else
{
// Success, display the locale name we found
wprintf(L"Locale Name for 0x10407 is %s\n", strNameBuffer);
}
// Get the LCID for the locale
lcid = LocaleNameToLCID(strNameBuffer, 0);
if (lcid == 0)
{
// There was an error
error = GetLastError();
}
else
{
// Success, print the round trip LCID
wprintf(L"LCID for %s is 0x%x\n", strNameBuffer, lcid);
}
}
/* This code example produces the following output:
Locale Name for 0x10407 is de-DE_phoneb
LCID for de-DE_phoneb is 0x10407
*/
Requirements
|
Minimum supported client | Windows Vista |
|---|---|
|
Minimum supported server | Windows Server 2008 |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- National Language Support
- National Language Support Functions
- NLS: Name-based APIs Sample
- DownlevelLocaleNameToLCID
Send comments about this topic to Microsoft
Build date: 9/7/2011
