The DMProcessConfigXML function can be used on Windows CE 5 device to easily access configuration management subsystems.
As usual the documentation is not optimal and lacks real life examples. Here I'll detail how to setup a Wi-Fi connection programmatically in C++. This newly created connection will appear among all other connections created from the control panel. This method may be used (with other configuration service providers) to backup a PocketPC configuration.
A few things to keep in mind anytime:
- Error codes returned by the
DMProcessConfigXML syscall and its prototype are defined in cfgmgrapi.h header.
- GUIDs that define various destination types are defined in
connmgr.h header.
- Before trying to access the WiFi service make sure the driver is loaded and working. Read as: it won't work when the device is cradled and USB-connected.
- When you create a new configuration it gets listed into the connection list but I don't know anything about the priority. If you have more than one available networks what will be connected first? It seems to me that overwriting the settings of a connection forces it to be connected, but don't be so sure.
- If you add a connection with the name of another, already existing, one you are just overwriting the previous settings.
- If you query a connection which uses WEP and a key, you won't get back the key itself but only a nice set of asterisks.
- All the strings exchanged are wide-char strings.
- Don't rely on default values. Always specify all the parameters. If you don't, some of the default values may be in logical conflict with the one you specified. What happens then? Boh...
Now the real meat: 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>";
LPWSTR out = NULL;
HRESULT res = ::DMProcessConfigXML(in, CFGFLAG_PROCESS, &out);
delete[] out;
out will contain a copy of the configuration just inserted, and return value should be
S_OK.
Query works in the same way. There are some M$ examples about recursive query of all WiFi connections. Here's an example on how to query a specific connection.
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>";
LPWSTR out = NULL;
HRESULT res = ::DMProcessConfigXML(in, CFGFLAG_PROCESS, &out);
delete[] out;