GPRSNET GPRSWAP方式配置创建并连接 GprsXmlConfig.h: /*! * 通过wap-provisioningdoc方式设置gprs连接 * 使用方式:枚举网络找一个名为CMWAP_GPRS的连接,(如果找不到新建一个名为CMWAP_GPRS的网络连接), * 然后通过建立该连接来进行网络访问 */ class GprsXmlConfig { public: GprsXmlConfig(void); ~GprsXmlConfig(void); public: /* 创建一个名为CMWAP_GPRS的网络设置*/ BOOL CreateCmwapNetConfig(); /*选择名为CMWAP_GPRS的网络设置的GUID*/ BOOL findCmwapNetGuid(GUID&); public: /* 创建一个名为CMNET_GPRS的网络设置*/ BOOL CreateCmnetNetConfig(); BOOL InsertNetToCurrentAP(); /*选择名为CMNET_GPRS的网络设置的GUID*/ BOOL findCmNetNetGuid(GUID&); }; GprsXmlConfig.cpp #include "StdAfx.h" #include "GprsXmlConfig.h" #include <Cfgmgrapi.h> #include <connmgr.h> #include <connmgr_proxy.h> #pragma comment( lib,"cellcore.lib") #pragma comment(lib, "Aygshell.lib") GprsXmlConfig::GprsXmlConfig(void) { } GprsXmlConfig::~GprsXmlConfig(void) { } BOOL GprsXmlConfig::findCmwapNetGuid(GUID& guid) { BOOL rst = false; HRESULT hr = 0; int nIndex = 0; CONNMGR_DESTINATION_INFO DestInfo; //WCHAR wszDestGUIDStr[128]; while ( (hr = ConnMgrEnumDestinations(nIndex,&DestInfo)) == 0 ) { if (_tcscmp(_T("中国移动WAP设置"),DestInfo.szDescription)==0) { guid = DestInfo.guid; rst = true; break; } nIndex++; } return rst; } BOOL GprsXmlConfig::findCmNetNetGuid(GUID& guid) { BOOL rst = false; HRESULT hr = 0; int nIndex = 0; CONNMGR_DESTINATION_INFO DestInfo; //WCHAR wszDestGUIDStr[128]; while ( (hr = ConnMgrEnumDestinations(nIndex,&DestInfo)) == 0 ) { if (_tcscmp(_T("中国移动NET设置"),DestInfo.szDescription)==0) { guid = DestInfo.guid; rst = true; break; } nIndex++; } return rst; } BOOL GprsXmlConfig::CreateCmwapNetConfig() { //AfxMessageBox(_T("开始创建连接")); LPCWSTR g_wszFavoriteXml = L"<wap-provisioningdoc>" L" <characteristic type=/"CM_Networks/">" L" <characteristic type=/"中国移动WAP设置/">" L" <parm name=/"DestId/" value=/"{EA9A391E-7878-0D28-4CA2-21F8C61F1243}/"/>" L" </characteristic>" L" </characteristic>" L" <characteristic type=/"CM_GPRSEntries/">" L" <characteristic type=/"中国移动 GPRS 因特网/">" L" <parm name=/"DestId/" value=/"{EA9A391E-7878-0D28-4CA2-21F8C61F1243}/"/>" 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=/"HTTP-{EA9A391E-7878-0D28-4CA2-21F8C61F1243}/">" L" <parm name=/"SrcId/" value=/"{EA9A391E-7878-0D28-4CA2-21F8C61F1243}/"/>" 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 type=/"WAP-{EA9A391E-7878-0D28-4CA2-21F8C61F1243}/">" L" <parm name=/"SrcId/" value=/"{EA9A391E-7878-0D28-4CA2-21F8C61F1243}/"/>" L" <parm name=/"DestId/" value=/"{7022E968-5A97-4051-BC1C-C578E2FBA5D9}/"/>" L" <parm name=/"Proxy/" value=/"10.0.0.172:9201/"/>" L" <parm name=/"Enable/" value=/"1/"/>" L" <parm name=/"Type/" value=/"2/"/>" L" </characteristic>" L" </characteristic>" L"</wap-provisioningdoc>"; HRESULT hr = E_FAIL; LPWSTR wszOutput = NULL; hr = DMProcessConfigXML(g_wszFavoriteXml, CFGFLAG_PROCESS, &wszOutput); // if (hr==S_OK) // { // AfxMessageBox(_T("创建连接成功!")); // } if (wszOutput) { delete [] wszOutput; wszOutput=NULL; } return (hr==S_OK); } BOOL GprsXmlConfig::CreateCmnetNetConfig() { // AfxMessageBox(_T("开始创建连接")); LPCWSTR g_wszFavoriteXml = L"<wap-provisioningdoc>" L" <characteristic type=/"CM_Networks/">" L" <characteristic type=/"中国移动NET设置/">" L" <parm name=/"DestId/" value=/"{A6F03289-77B9-442d-BA5F-782DE8277792}/"/>" L" </characteristic>" L" </characteristic>" L" <characteristic type=/"CM_GPRSEntries/">" L" <characteristic type=/"Internet Connect/">" L" <parm name=/"DestId/" value=/"{A6F03289-77B9-442d-BA5F-782DE8277792}/"/>" 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=/"cmnet/"/>" 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"</wap-provisioningdoc>"; HRESULT hr = E_FAIL; LPWSTR wszOutput = NULL; hr = DMProcessConfigXML(g_wszFavoriteXml, CFGFLAG_PROCESS, &wszOutput); if (hr==S_OK) { // AfxMessageBox(_T("创建连接成功!")); } if (wszOutput) { delete [] wszOutput; wszOutput=NULL; } return (hr==S_OK); } // 在当前接入点上添加选项 BOOL GprsXmlConfig::InsertNetToCurrentAP() { AfxMessageBox(_T("开始创建连接")); LPCWSTR g_wszFavoriteXml = L"<wap-provisioningdoc>" L" <characteristic type=/"CM_GPRSEntries/">" L" <characteristic type=/"Internet Connect/">" L" <parm name=/"DestId/" value=/"{436EF144-B4FB-4863-A041-8F905A62C572}/"/>" L" <characteristic type=/"DevSpecificCellular/">" L" <parm name=/"GPRSInfoAccessPointName/" value=/"cmnet/"/>" L" </characteristic>" L" </characteristic>" L" </characteristic>" L"</wap-provisioningdoc>"; HRESULT hr = E_FAIL; LPWSTR wszOutput = NULL; hr = DMProcessConfigXML(g_wszFavoriteXml, CFGFLAG_PROCESS, &wszOutput); if (hr==S_OK) { AfxMessageBox(_T("创建连接成功!")); } if (wszOutput) { delete [] wszOutput; wszOutput=NULL; } return (hr==S_OK); }