Create and delete a GPRS Access Point under Wm

Source: Internet
Author: User

Preface: when we develop the networking function on a mobile phone, we can use the access point set on the mobile phone to connect the mobile phone. However, sometimes the mobile phone settings may not be correct, in this case, if you still connect to the Internet using the mobile phone access point, there is an error in the program. We can create an access point on the mobile phone through the program, and then connect the network through the access point.

Create Access Point

void CCommunicate::CreateAccessPoint()   {           CString strFavoriteXml =                    L"<wap-provisioningdoc>"                    L"<characteristic type=\"CM_Networks\">"                  L"<characteristic type=\"Test_GPRS\">"                  L"<parm name=\"DestId\" value=\"{D1D06580-C364-55ec-9421-6ACF34129C58}\" />"                  L"</characteristic>"                  L"</characteristic>"                  L"<characteristic type=\"CM_GPRSEntries\">"                  L"<characteristic type=\"Test_GPRS\">"                  L"<parm name=\"DestId\" value=\"{D1D06580-C364-55ec-9421-6ACF34129C58}\" />"                  L"<characteristic type=\"DevSpecificCellular\">"                  L"<parm name=\"BearerInfoValid\" value=\"1\" />"                  L"<parm name=\"GPRSInfoValid\" value=\"1\" />"                  L"<parm name=\"GPRSInfoProtocolType\" value=\"2\" />"                  L"<parm name=\"GPRSInfoL2ProtocolType\" value=\"PPP\" />"                  L"<parm name=\"GPRSInfoAccessPointName\" value=\"cmwap\" />"                  L"<parm name=\"GPRSInfoAddress\" value=\"\" />"                  L"<parm name=\"GPRSInfoDataCompression\" value=\"1\" />"                  L"<parm name=\"GPRSInfoHeaderCompression\" value=\"1\" />"                  L"<parm name=\"GPRSInfoParameters\" value=\"\" />"                  L"</characteristic>"                  L"</characteristic>"                  L"</characteristic>"                  L"<characteristic type=\"CM_ProxyEntries\">"                  L"<characteristic type=\"WAP\">"                  L"<parm name=\"SrcId\" value=\"{D1D06580-C364-55ec-9421-6ACF34129C58}\" />"                  L"<parm name=\"DestId\" value=\"{436EF144-B4FB-4863-A041-8F905A62C572}\" />"                  L"<parm name=\"Proxy\" value=\"10.0.0.172:80\" />"                  L"<parm name=\"Enable\" value=\"1\" />"                  L"<parm name=\"Type\" value=\"1\" />"                  L"</characteristic>"                  L"</characteristic>"                  L"</wap-provisioningdoc>";             LPWSTR pszwXMLout = NULL;           HRESULT hr = DMProcessConfigXML(strFavoriteXml, CFGFLAG_PROCESS, &pszwXMLout);             if ( pszwXMLout )           {                   delete [] pszwXMLout;                   pszwXMLout = NULL;           }   } 

Use the created Access Point

int CCommunicate::CreateConnection( HANDLE *phConnection )   {           HRESULT            hResult;           //        HANDLE             phConnection;           DWORD              dwStatus;            DWORD              dwResult;           CONNMGR_DESTINATION_INFO cdi;           int i;           for(i = 0; SUCCEEDED(ConnMgrEnumDestinations(i, &cdi)); i++)           {                   if (0 == wcscmp(cdi.szDescription, _T("Test_GPRS")))                           break;           }           hResult = ConnMgrEnumDestinations(i, &cdi);           if (FAILED(hResult))           {                   AfxMessageBox(L"ConnMgrEnumDestinations Error!");                   return FALSE;           }           CONNMGR_CONNECTIONINFO ConnInfo;            ZeroMemory( &ConnInfo, sizeof( ConnInfo ) );            ConnInfo.cbSize = sizeof( ConnInfo );            ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;            ConnInfo.dwPriority = CONNMGR_PRIORITY_HIPRIBKGND;            ConnInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_WAP;           ConnInfo.bExclusive = FALSE;                    ConnInfo.bDisabled = FALSE;            ConnInfo.guidDestNet = cdi.guid;           TRACE(_T("ConnectToHttpServer\n") );             dwStatus = CONNMGR_STATUS_CONNECTED;             hResult = ConnMgrEstablishConnectionSync( &ConnInfo, phConnection, 75000, &dwStatus );           if ( hResult != S_OK )           {                   TRACE(_T("ConnMgrEstablishConnection is error\n") );                   dwResult = GetLastError();                   // for debug                   CString tmp;                   tmp.Format(_T("%ld"), dwStatus);                   AfxMessageBox( tmp, MB_OK);                   return S_FALSE;           }           else          {                   AfxMessageBox(_T("ConnMgrEstablishEonnection is success\n"), MB_OK);                   // do something           }           return S_OK;   } 

Delete the created Access Point

void CCommunicate::ReleaseAccessPoint()   {           CString strFavoriteXml =                    L"<wap-provisioningdoc>"                  L"<characteristic type=\"CM_Networks\">"                  L"<nocharacteristic type=\"Test_GPRS\"/>"                  L"</characteristic>"                    L"</wap-provisioningdoc>";           LPWSTR pszwXMLout = NULL;           HRESULT hr = DMProcessConfigXML(strFavoriteXml, CFGFLAG_PROCESS, &pszwXMLout);             if ( hr == S_OK)           {                   AfxMessageBox( L"Delete access point success!");           }           else          {                   AfxMessageBox( L"Delete access point failed!");           }           if ( pszwXMLout )           {                   delete [] pszwXMLout;                   pszwXMLout = NULL;           }   }  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.