Expand Minimize

LocaleNameToLCID function

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.

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.

Remarks

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.

Windows Phone 8: This API is supported.

Windows Phone 8.1: This API is supported.

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 [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Header

Winnls.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

National Language Support
National Language Support Functions
NLS: Name-based APIs Sample
DownlevelLocaleNameToLCID

 

 

Community Additions

ADD
Show:
© 2014 Microsoft