DMProcessConfigXML 使用实例
下面提供一些函数DMProcessConfigXML一些使用实例,函数的具体使用方法参见MSDN。
1、创建cmnet连接
LPCWSTR strFavoriteXml =
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>"; //DestID是自己定义的GUID,当然,也有已经定义好的GUID可以直接用
LPWSTR pszwXMLout = NULL;
HRESULT hr = DMProcessConfigXML(strFavoriteXml, CFGFLAG_PROCESS, &pszwXMLout);
if ( pszwXMLout )
{
delete [] pszwXMLout;
pszwXMLout = NULL;
}
2、创建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;
}
3、获取某个连接的接入点
LPCTSTR szFormat =
L"<wap-provisioningdoc>"
L"<characteristic type=\"CM_GPRSEntries\">"
L"<characteristic type=\"%s\">"
L"<characteristic type=\"DevSpecificCellular\">"
L"<parm-query name=\"GPRSInfoAccessPointName\"/>"
L"</characteristic>"
L"</characteristic>"
L"</characteristic>"
L"</wap-provisioningdoc>";
//%s为 "移动梦网(GPRS)" "GPRS连接互联网" 等,
//可以用ConnMgrQueryDetailedStatus枚举,CONNMGR_CONNECTION_DETAILED_STATUS的szDescription
4、卸载应用程序
LPCTSTR szFormat =
L"<wap-provisioningdoc>"
L"<characteristic type="UnInstall">"
L"<characteristic type="[AppName]">"
L"<parm name="uninstall" value="1"/>"
L"</characteristic>"
L"</characteristic>"
L"</wap-provisioningdoc>"
//[AppName] = 注册表中对应的该软件的名称 一般是:生成cab包使用的inf中的provider和appname的组合
//如:provider = aaa appname = bbb <characteristic type="aaa bbb"> 然后用DMProcessConfigXML来处理
5、关闭硬件按钮声音
LPCTSTR szFormat =
L"<wap-provisioningdoc>"
L"<characteristic type="Sounds">"
L"<characteristic type="ControlPanel\Sounds\KeyPress">"
L"<parm name="Mode" value="1"/> <!-- 0=none, 1=tone, 2=click -->"
L"</characteristic>"
L"</characteristic>"
L"</wap-provisioningdoc>"
//使用DMProcessConfigXML()函数通过配置管理器发送上面的XML配置数据。
6、创建一封新的email
LPCWSTR strFavoriteXml =
L"<wap-provisioningdoc>"
L"<characteristic type="EMAIL2">"
L"<characteristic type="[GUID]">"
L"<parm name="SERVICENAME" value="[MailServiceName]"/>"
L"<parm name="SERVICETYPE" value="POP3"/>"
L"<parm name="INSERVER" value="[popserver]"/>"
L"<parm name="OUTSERVER" value="[smtpserver]"/>"
L"<parm name="AUTHNAME" value="[alias]"/>"
L"<parm name="AUTHSECRET" value="[password]"/>"
L"<parm name="DOMAIN" value="[domain]"/>"
L"<parm name="REPLYADDR" value="[emailAddress]"/>"
L"</characteristic>"
L"</characteristic>"
L"</wap-provisioningdoc>"
//[…]中的参数都是自定义的
7、创建Wi-Fi连接
//This XML will add or overwrite a Wi-Fi access point connection with SSID COWO, no encryption, open authentication.
//This connection is regarded as an internet connection.
LPCWSTR in = \
L"<wap-provisioningdoc>"
L" <characteristic type=\"Wi-Fi\"> "
L" <characteristic type=\"access-point\"> "
L" <characteristic type=\"COWO\"> "
L" <parm name=\"DestId\" value=\"{436EF144-B4FB-4863-A041-8F905A62C572}\"/>"
L" <parm name=\"AdHoc\" value=\"0\"/>"
L" <parm name=\"Authentication\" value=\"0\"/>"
L" <parm name=\"Encryption\" value=\"1\"/>"
L" <parm name=\"KeyProvided\" value=\"0\"/>"
L" <parm name=\"NetworkKey\" value=\"\"/>"
L" <parm name=\"KeyIndex\" value=\"1\"/>"
L" <parm name=\"Use8021x\" value=\"0\"/>"
L" <parm name=\"EAPType\" value=\"25\"/>"
L" </characteristic>"
L" </characteristic>"
L" </characteristic>"
L"</wap-provisioningdoc>";
8、枚举Wi-Fi连接点
//Here's an example on how to query a specific connection.
LPCWSTR in =
L"<wap-provisioningdoc>"
L" <characteristic type=\"Wi-Fi\"> "
L" <characteristic type=\"access-point\"> "
L" <characteristic-query type=\"COWO\" /> "
L" </characteristic>"
L" </characteristic>"
L"</wap-provisioningdoc>";