nsresult nsAutodial::DialDefault(const PRUnichar* hostName) { #ifdef WINCE_WINDOWS_MOBILE HANDLE connectionHandle; // always use http:// nsString theURL; theURL.Append(L"http://"); theURL.Append(hostName); GUID networkUID; ConnMgrMapURL(theURL.get(), &networkUID, 0); // Make the connection to the new network CONNMGR_CONNECTIONINFO conn_info; memset(&conn_info, 0, sizeof(conn_info)); conn_info.cbSize = sizeof(conn_info); conn_info.dwParams = CONNMGR_PARAM_GUIDDESTNET; conn_info.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE; conn_info.guidDestNet = networkUID; conn_info.bExclusive = FALSE; conn_info.bDisabled = FALSE; conn_info.dwFlags = CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_WAP | CONNMGR_FLAG_PROXY_SOCKS4 | CONNMGR_FLAG_PROXY_SOCKS5 | CONNMGR_FLAG_NO_ERROR_MSGS; DWORD status; HRESULT result = ConnMgrEstablishConnectionSync(&conn_info, &connectionHandle, 60000, &status); if (conn_info.guidDestNet != autodial_DestNetInternet && (result != S_OK || status != CONNMGR_STATUS_CONNECTED)) { conn_info.guidDestNet = autodial_DestNetInternet; result = ConnMgrEstablishConnectionSync(&conn_info, &connectionHandle, 60000, &status); } if (result != S_OK || status != CONNMGR_STATUS_CONNECTED) return NS_ERROR_FAILURE; return NS_OK; #else return NS_ERROR_FAILURE; #endif }
bool CNetRequestImpl::SetupInternetConnection(LPCTSTR url) { #if defined (_WIN32_WCE) int iNetwork; HRESULT hResult = E_FAIL; DWORD dwStatus; static HANDLE hConnection = NULL; // cleanup the old connection if(NULL != hConnection) { hResult = ConnMgrConnectionStatus( hConnection, &dwStatus ); if( SUCCEEDED(hResult) ) { LOG(INFO) + "Internet connection exist, use it"; if( dwStatus & CONNMGR_STATUS_CONNECTED ) return true; } ConnMgrReleaseConnection(hConnection, FALSE); LOG(INFO) + "Internet connection droped, open new one"; hConnection = NULL; } // get the right network to connect to iNetwork = 0; //CONNMGR_DESTINATION_INFO DestInfo; GUID pguid; if( FAILED( ConnMgrMapURL(url, &pguid, NULL) ) ) return false; //while( SUCCEEDED(ConnMgrEnumDestinations(iNetwork++, &DestInfo))) { LOG(INFO) + "Try establish Internet connection"; // actually try to establish the connection CONNMGR_CONNECTIONINFO ConnInfo; ZeroMemory(&ConnInfo, sizeof(ConnInfo)); ConnInfo.cbSize = sizeof(ConnInfo); ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET; ConnInfo.dwPriority = CONNMGR_PRIORITY_HIPRIBKGND;//CONNMGR_PRIORITY_USERBACKGROUND; #if ( _WIN32_WCE >= 0x500 ) ConnInfo.dwFlags = CONNMGR_FLAG_NO_ERROR_MSGS; #endif ConnInfo.guidDestNet = pguid; hResult = ConnMgrEstablishConnection(&ConnInfo, &hConnection); // check to see if the attempt failed int count = 0; while(SUCCEEDED(hResult) && count++ < 60 ) { LOG(INFO) + "Wait for connect (" + count + ")"; DWORD dwResult = WaitForSingleObject(hConnection, 1000); if (dwResult == (WAIT_OBJECT_0)) { hResult=ConnMgrConnectionStatus(hConnection,&dwStatus); if( SUCCEEDED(hResult) ) { if( dwStatus & CONNMGR_STATUS_CONNECTED ) { LOG(INFO) + "Connected"; return true; } if( dwStatus & CONNMGR_STATUS_WAITINGCONNECTION ) { continue; } break; } } } } LOG(ERROR) + "Failed to connect"; return false; #else return true; #endif //_WIN32_WCE }