LocaleNameToLCID function (winnls.h)

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.



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


[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

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.

If the locale provided is a transient locale or a CLDR (Unicode Common Locale Data Repository) locale, then the LCID returned is 0x1000.

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.


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.


#include "stdafx.h"
#include "windows.h"
#include "stdio.h"

int _cdecl main(
    int argc,
    char *argv[])
    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();
        // 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();
        // 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



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


NLS: Name-based APIs Sample

National Language Support

National Language Support Functions