擷取當前GPRS接入狀態

來源:互聯網
上載者:User

 
//////////////////////////////////////////////////////////////////////////////////////<br />// chengchenz@mail.csdn.net<br />//<br />// GetAPN.cpp : Defines the entry point for the application.<br />//<br />//////////////////////////////////////////////////////////////////////////////////////</p><p>#include <stdlib.h><br />#include <windows.h></p><p>#include <connmgr.h><br />#include <Connmgr_status.h><br />#include <Cfgmgrapi.h><br />#include <strsafe.h></p><p>//<br />// FUNCTION: GetAPNFromEntryName(LPCTSTR szEntryName, LPTSTR szAPN, int cchAPN)<br />//<br />// PURPOSE: Get the GPRS Access Point Name form the Entry Name<br />//<br />HRESULT GetAPNFromEntryName(LPCTSTR szEntryName, LPTSTR szAPN, int cchAPN)<br />{<br /> // parm query formating string of "CM_GPRSEntries Configuration Service Provider"<br /> LPCTSTR szFormat = TEXT("<wap-provisioningdoc>")<br /> TEXT(" <characteristic type=/"CM_GPRSEntries/">")<br /> TEXT(" <characteristic type=/"%s/">")<br /> TEXT(" <characteristic type=/"DevSpecificCellular/">")<br /> TEXT(" <parm-query name=/"GPRSInfoAccessPointName/"/>")<br /> TEXT(" </characteristic>")<br /> TEXT(" </characteristic>")<br /> TEXT(" </characteristic>")<br /> TEXT("</wap-provisioningdoc>");<br /> HRESULT hr = E_FAIL;<br /> LPTSTR szOutput = NULL;</p><p> if(NULL == szEntryName)<br /> return E_INVALIDARG;</p><p> // prepare the query string with the special entry name<br /> LPTSTR szInput = new TCHAR[_tcslen(szFormat) + _tcslen(szEntryName) + 10];<br /> if(NULL == hr)<br /> return E_OUTOFMEMORY;</p><p> _stprintf(szInput, szFormat, szEntryName);</p><p> // Process the XML.<br /> hr = DMProcessConfigXML(szInput, CFGFLAG_PROCESS, &szOutput);</p><p> if(S_OK == hr)<br /> {<br /> hr = E_FAIL;</p><p> // find the value of GPRSInfoAccessPointName param<br /> LPTSTR szAPNStrStart = _tcsstr(szOutput, TEXT("value=/""));<br /> if(NULL != szAPNStrStart)<br /> {<br /> szAPNStrStart += _tcslen(TEXT("value=/""));</p><p> // find the end of value string<br /> LPTSTR szAPNStrEnd = _tcsstr(szAPNStrStart, TEXT("/""));<br /> if(NULL != szAPNStrEnd)<br /> {<br /> // set the null char at the end of the value string<br /> *szAPNStrEnd = TEXT('/0');</p><p> // get the final Access Point Name string<br /> _tcsncpy(szAPN, szAPNStrStart, cchAPN);<br /> hr = S_OK;<br /> }<br /> }</p><p> }</p><p> // the caller must delete the XML returned from DMProcessConfigXML.<br /> delete[] szOutput;</p><p> // clear the input string<br /> delete[] szInput;</p><p> return hr;<br />}</p><p>//<br />// we will enum the all connected GPRS<br />// and display their entry name and APN on the message box<br />//<br />int WINAPI WinMain(HINSTANCE hInstance,<br /> HINSTANCE hPrevInstance,<br /> LPTSTR lpCmdLine,<br /> int nCmdShow)<br />{<br /> TCHAR szAPN[200];</p><p> DWORD dwSize = 0;<br /> HRESULT hr = E_FAIL;</p><p> //<br /> // Get the the required size of the buffer<br /> // with which the function needs to be called on the next attempt.<br /> //<br /> hr = ConnMgrQueryDetailedStatus(NULL, &dwSize);<br /> if(STRSAFE_E_INSUFFICIENT_BUFFER != hr)<br /> return hr;</p><p> LPBYTE pBuffer = new BYTE[dwSize];<br /> if(NULL == pBuffer)<br /> return E_OUTOFMEMORY;</p><p> //<br /> // Get the connection information<br /> //<br /> hr = ConnMgrQueryDetailedStatus((CONNMGR_CONNECTION_DETAILED_STATUS*)pBuffer, &dwSize);<br /> if(S_OK == hr)<br /> {</p><p> //<br /> // Enum each connection entry<br /> //<br /> CONNMGR_CONNECTION_DETAILED_STATUS* cmStatus = (CONNMGR_CONNECTION_DETAILED_STATUS*)pBuffer;<br /> while(NULL != cmStatus)<br /> {<br /> // find the connected GPRS entry<br /> if((cmStatus->dwParams & (CONNMGRDETAILEDSTATUS_PARAM_TYPE |CONNMGRDETAILEDSTATUS_PARAM_DESCRIPTION | CONNMGRDETAILEDSTATUS_PARAM_CONNSTATUS)) &&CM_CONNTYPE_CELLULAR == cmStatus->dwType &&CONNMGR_STATUS_CONNECTED == cmStatus->dwConnectionStatus && NULL != cmStatus->szDescription)<br /> {<br /> // get the connected GPRS APN<br /> if(S_OK == GetAPNFromEntryName(cmStatus->szDescription, szAPN, 200))<br /> MessageBox(NULL, szAPN, cmStatus->szDescription, MB_OK | MB_ICONINFORMATION);</p><p> }</p><p> // test the next one<br /> cmStatus = cmStatus->pNext;<br /> }<br /> }</p><p> // clear the buffer<br /> delete pBuffer;</p><p> return 0;<br />}<br />

 

備忘:#include <Connmgr_status.h>要在wince 4.2以上版本才支援

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.