NS_IMETHODIMP nsNotifyAddrListener::GetIsLinkUp(PRBool *aIsUp) { #ifdef WINCE_WINDOWS_MOBILE DWORD status; HRESULT result = ConnMgrConnectionStatus(mConnectionHandle, &status); if (FAILED(result)) { *aIsUp = PR_FALSE; return NS_ERROR_FAILURE; } *aIsUp = status == CONNMGR_STATUS_CONNECTED; #else *aIsUp = PR_TRUE; #endif return NS_OK; }
NS_IMETHODIMP nsNotifyAddrListener::GetLinkStatusKnown(PRBool *aIsKnown) { #ifdef WINCE_WINDOWS_MOBILE DWORD status; HRESULT result = ConnMgrConnectionStatus(mConnectionHandle, &status); if (FAILED(result)) { *aIsKnown = PR_FALSE; return NS_ERROR_FAILURE; } *aIsKnown = status != CONNMGR_STATUS_UNKNOWN; #else *aIsKnown = PR_TRUE; #endif return NS_OK; }
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 }