Windows: Get LCID from locale string?

I have string data representing locales such as "fr" or "en". I need to convert it to the corresponding LCID values, for example 0x80cor 0x409. Is there a function or macro for this?

I am using C ++ on Windows 7.

+3
source share
2 answers

These are LCID values, not sure what LID means. You can get them from GetLocaleInfoEx (), available in Vista and above. You need to pass the name of the locale, for example, "en-US", necessary for the language. For instance:

#include "stdafx.h"
#include <windows.h>
#include <assert.h>

int _tmain(int argc, _TCHAR* argv[])
{
    LCID lcid = 0;
    BOOL ok = GetLocaleInfoEx(L"en-US", LOCALE_RETURN_NUMBER | LOCALE_ILANGUAGE, (LPWSTR)&lcid, sizeof(lcid));
    assert(ok);
    wprintf(L"LCID = %04x\n", lcid);
    return 0;
}

Output: LCID = 0409

+4
source
+1

Source: https://habr.com/ru/post/1754469/


All Articles