Oh man, it took forever, so I might as well post it as it suits me.
// Returns only the first null terminated string (selected Windows display language).
std::basic_string<TCHAR> GetWindowsDisplayLanguageFromRegistry()
{
LPCTSTR subKey = _T("Control Panel\\International\\User Profile\\");
LPCTSTR valueName = _T("Languages");
DWORD bufferSize = 0;
// Check buffer size.
if (RegGetValue(HKEY_CURRENT_USER, subKey, valueName, RRF_RT_REG_MULTI_SZ, nullptr, nullptr, &bufferSize) == ERROR_SUCCESS)
{
// Manage memory.
std::vector<TCHAR> value(bufferSize / sizeof(TCHAR));
// Get registry key value.
if (RegGetValue(HKEY_CURRENT_USER, subKey, valueName, RRF_RT_REG_MULTI_SZ, nullptr, &value[0], &bufferSize) == ERROR_SUCCESS)
{
// Ensure null-termination.
value[bufferSize / sizeof(TCHAR)] = _T('\0');
std::basic_string<TCHAR> firstString(value.data());
return firstString;
}
}
return std::basic_string<TCHAR>();
}