Programming Tips - Win32: Get proxy server from registry

Date: 2021jul20 Platform: win32 Language: C/C++ Q. Win32: Get proxy server from registry A. Here is my code to get the control panel proxy server. It uses my registry class but its pretty clear how it works. There is a way to exclude some hosts but that's non done here.
void GetProxyServerFromRegistry(LPSTR szServer, const size_t sizeServer) { szServer[0] = '\0'; CMyRegistry reg; LPCSTR key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; if (!reg.ChangeTo(HKEY_CURRENT_USER, key)) { Debug(__FUNCTION__ ": Could not change to %s\n", key); return; } DWORD dwEnabled; if (!reg.GetDword("ProxyEnable", &dwEnabled)) { Debug(__FUNCTION__ ": ProxyEnable key seems to be missing (this is normal)\n"); return; } if (!dwEnabled) { Debug(__FUNCTION__ ": Proxy is disabled (this is normal)\n"); return; } if (!reg.GetString("ProxyServer", szServer, sizeServer)) { Debug(__FUNCTION__ ": ProxyServer key is not present (this is normal)\n"); return; } return; }