GetDynamicTimeZoneInformation does not always work. The minimum supported versions are Windows Vista, Windows Server 2008, and Windows Phone 8. So for anything below, GetTimeZoneInformation better.
However, another problem sometimes returns StandardName or DaylightName empty. In this case, you must use the Windows registry. Here is a function taken from gnu cash that has also been modified from glib.
static std::string windows_default_tzname(void) { const char *subkey = "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"; constexpr size_t keysize{128}; HKEY key; char key_name[keysize]{}; unsigned long tz_keysize = keysize; if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, subkey, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { if (RegQueryValueExA(key, "TimeZoneKeyName", nullptr, nullptr, (LPBYTE)key_name, &tz_keysize) != ERROR_SUCCESS) { memset(key_name, 0, tz_keysize); } RegCloseKey(key); } return std::string(key_name); }
source share