I want to store the locale name and code page appended to it in a buffer, what should be the ideal size of the buffer?.
From winnt.h
// Maximum Locale Name Length in Windows
// Locale names are preferred to the deprecated LCID/LANGID concepts.
//
// Locale names should follow the BCP47 recommendations and typically
// include language, script, regional variant, and perhaps additional specifiers.
// BCP47 allows some variation, eg: en-US is preferred to en-Latn-US.
#define LOCALE_NAME_MAX_LENGTH 85
As we can see LOCALE_NAME_MAX_LENGTH is for locale name without code page, eg: "en-US", But I want to store "en-US.1252", "English_United States.1252" etc..
What is the standard maximum length allowed for the code page?
Actually I want to do the following. I am using an array of 128 wide characters, I want to know what is the optimal size for the same?
size_t buffer_size;
wchar_t wc_locale_name[128];
wchar_t buffer[128];
wchar_t wc_full_locale_name[128];
buffer_size = _countof(buffer);
wmemset(wc_locale_name, 0, buffer_size);
wmemset(buffer, 0, buffer_size);
wmemset(strbuf, 0, buffer_size);
MultiByteToWideChar(CP_ACP, 0, "en-US", len, wc_locale_name,
LOCALE_NAME_MAX_LENGTH);
if (GetLocaleInfoEx(wc_locale_name, LOCALE_SENGLISHLANGUAGENAME, buffer,
buffer_size))
{
len = swprintf(wc_full_locale_name, buffer_size, L"%ls", buffer);
wmemset(buffer, 0, buffer_size);
if (GetLocaleInfoEx(wc_locale_name, LOCALE_SENGLISHCOUNTRYNAME,
buffer, buffer_size))
{
len += swprintf(wc_full_locale_name + len, buffer_size - len, L"_%ls",
buffer);
wmemset(buffer, 0, buffer_size);
if (GetLocaleInfoEx(wc_locale_name, LOCALE_IDEFAULTANSICODEPAGE,
buffer, buffer_size))
{
len = swprintf(wc_full_locale_name + len, buffer_size - len, L".%ls",
buffer);
}
}
}