商务合作:179001057@qq.com

利用系统接入点访问网络

技术2022-05-11  0


某平台价值19860元的编程课程资料免费领取【点我领取】


 如何利用系统当前接入点访问网络,并获取当前代理参数呢?

 

 // 1 初始化 CONNMGR_CONNECTIONINFO memset(&m_ccInfo, 0, sizeof(m_ccInfo)); m_ccInfo.cbSize = sizeof(m_ccInfo); m_ccInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET; m_ccInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP|CONNMGR_FLAG_PROXY_WAP; m_ccInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE; m_ccInfo.bExclusive=FALSE;  m_ccInfo.bDisabled=FALSE;

 

 // 2 进行URL映射 DWORD dwIndex = 0; ConnMgrMapURL(L"http://www.sohu.com", &m_ccInfo.guidDestNet, &dwIndex);

 

 // 3 启动异步连接 m_hGPRSConn = NULL; DWORD dwStatus = 0; if(ConnMgrEstablishConnection(&m_ccInfo,&m_hGPRSConn)== E_FAIL)          return false;

 

 // 4 等待一段时间后获取网络连接状态 DWORD dwStatus = 0; HRESULT hr = ConnMgrConnectionStatus (m_hGPRSConn, &dwStatus); if ( SUCCEEDED(hr) ) {  if (dwStatus == CONNMGR_STATUS_CONNECTED)  {     return true;  } } return false;

 // 5 获取当前连接的代理 PROXY_CONFIG  ProxyInfo= {0}; memset(&ProxyInfo, 0, sizeof(PROXY_CONFIG));

 

 ProxyInfo.dwType = CONNMGR_FLAG_PROXY_HTTP;//| CONNMGR_FLAG_PROXY_WAP;  DWORD dwSize = sizeof(PROXY_CONFIG); LRESULT hr = ConnMgrProviderMessage(m_hGPRSConn,&IID_ConnPrv_IProxyExtension,          0, 0, 0, (PBYTE)&ProxyInfo, dwSize); if (hr != S_OK) return false;

 

 CString strProxyServer = ProxyInfo.szProxyServer; int iPos = strProxyServer.Find(_T(":")); if(-1 == iPos) return false; strProxy = strProxyServer.Left(iPos); CString strTemp = strProxyServer.Right(strProxyServer.GetLength() - iPos - 1); char* pszTemp = NULL; StrTCHAR2Char(strTemp, &pszTemp); iPort = atoi(pszTemp); delete[] pszTemp;


最新回复(0)