LocaleNameToLCID function (winnls.h)

Converts a locale name to a locale identifier.

Syntax

LCID LocaleNameToLCID(
  [in] LPCWSTR lpName,
  [in] DWORD   dwFlags
);

Parameters

[in] lpName

Pointer to a null-terminated string representing a locale name, or one of the following predefined values.

[in] dwFlags

Prior to Windows 7:Reserved; should always be 0.

Beginning in Windows 7: Can be set to LOCALE_ALLOW_NEUTRAL_NAMES to allow the return of a neutral LCID.

Return value

If successful, returns the locale identifier corresponding to the locale name.

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, is a transient locale, or is a CLDR (Unicode Common Locale Data Repository) locale, 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 ERROR_INVALID_PARAMETER if any of the parameter values are invalid.

Remarks

For custom locales, including those created by Microsoft, your applications should prefer locale names over locale identifiers. See The deprecation of LCIDs for more info.

Beginning in Windows 8: If your app passes language tags to this function from the Windows.Globalization namespace, it must first convert the tags by calling ResolveLocaleName.

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

Requirement Value
Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header winnls.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also

DownlevelLocaleNameToLCID

NLS: Name-based APIs Sample

National Language Support

National Language Support Functions