Programming Tips - CInternetSession: use proxy set in Control Panel

Date: 2021may26 Framework: MFC Language: C/C++ Q. CInternetSession: use proxy set in Control Panel A. Its not automatic. There are 2 steps: 1. Read the proxy info from the registry (I could not find an API) 2. Use it with CInternetSession 1. Read from the registry
In HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings (Notice no space in CurrentVersion but there is a space in Internet Settings) Read DWORD ProxyEnable 1 = enabled Read String ProxyServer For me I get host:port - eg example.com:8080 ie more than just the server. But I just use the whole string.
2. If the proxy is enabled and the ProxyServer string is non-empty use it when contructing your instance of CInternetSession
LPCTSTR pstrAgent = NULL; const DWORD dwFlags = 0; DWORD dwAccessType = PRE_CONFIG_INTERNET_ACCESS; LPCTSTR pstrProxyBypass = NULL; const CString strProxyName = GetProxyServerFromRegistry(); if (!strProxyName.IsEmpty()) { dwAccessType |= INTERNET_OPEN_TYPE_PROXY; } CMyInternetSession session(pstrAgent, dwAccessType, strProxyName, pstrProxyBypass, dwFlags); // Now use, `session`