GetSystemDefaultLocaleName function (winnls.h)

Retrieves the system default locale name.

Note  It is recommended that applications call GetUserDefaultLocaleName in preference over this function. This is due to the user locale generally being more useful and accurate for the user than the system locale.

Note  The application should call this function in preference to GetSystemDefaultLCID if designed to run only on Windows Vista and later.


int GetSystemDefaultLocaleName(
  [out] LPWSTR lpLocaleName,
  [in]  int    cchLocaleName


[out] lpLocaleName

Pointer to a buffer in which this function retrieves the locale name.

[in] cchLocaleName

Size, in characters, of the output buffer indicated by lpLocaleName. The maximum possible character length of a locale name (including a terminating null character) is the value of LOCALE_NAME_MAX_LENGTH. This is the recommended size.

Return value

Returns a value greater than 0 that indicates the length of the locale name, including the terminating null character, if successful.

This 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_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.


This function can retrieve data from custom locales. Data is not guaranteed to be the same from computer to computer or between runs of an application. If your application must persist or transmit data, see Using Persistent Locale Data.


An example showing the use of this function can be found in NLS: Name-based APIs Sample.


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




Mapping Locale Data

National Language Support

National Language Support Functions