程序中如果要使用http或socket连接服务器,需要先连接网络。ConnMgrEstablishConnectionSync函数中的CONNMGR_CONNECTIONINFO参数,不论采用IID_DestNetWAP还是IID_DestNetInternet,似乎都要依赖于手机上的接入点设置。都怪中国移动非要搞什么CMNET、CMWAP,中国特色的通信公司。
可以自行创建一接入点。以下代码创建一个CMWAP接入点:
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;
}