Hi all,

This question partially related to one of my old question.

Reading the time zone information. Now I'm try to do it in this way. User enter the time offset. Using that value search the registry and find the time zone name. Where I'm stuck is how to search the registry. Here what I'm try up to now.

HKEY hKey;// Handle to the registry
	DWORD dwType = REG_SZ;// Data type

	char buf[255];// Data
	DWORD dwBufSize = sizeof(buf);

	// Sub handle to the registry
	const char* subKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\Afghanistan Standard Time";

	// Open the handler
	if(RegOpenKey(HKEY_LOCAL_MACHINE, subKey, &hKey) == ERROR_SUCCESS)
	{
		// Do the processing, find the name
		if(RegQueryValueEx(hKey, "Std", 0, &dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS)
		{
			AfxMessageBox(buf);
		}
		else
		{
			AfxMessageBox("Error in reading values.", MB_OK);
		}
		// Close the handler
		RegCloseKey(hKey);
	}
	else
	{
		AfxMessageBox("Error in reading registry.", MB_OK);
	}

This code is work for Afghanistan Standard Time. How can I iteratively change until found the correct offset.

call RegEnumKey() to iterate through all the timezone keys. The Display name contains the timezone offset from GMT. You need to create a string in similar format so that it can be compared to what's in the registry.

Thanks for the information.

What I'm going to do is, using Display found the time offset, use a substring to do that, and compared it with the user input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.