Log in

View Full Version : Device Configuration Using .NET CF


Robert Levy
11-17-2003, 10:04 PM
The Smartphone includes some cool features under the covers that allow mobile operators, enterprises, and developers to make configuration changes to a device using XML. This XML can be sent to the device over the air, through a desktop, and through custom applications running on the device. Accessing this functionality from applications written in C++ is pretty straightforward using the DMProcessConfigXML function. However, doing this from a .NET Compact Framework app requires a bit of work. Version 2 of of the Compact Framework will make this really easy but in the mean time, feel free to use my C# DMProcessConfigXML wrapper. This works on Smartphone 2003 and Pocket PC 2003.<!>using System;<br />using System.Runtime.InteropServices;<br /><br />namespace DeviceConfigLib<br />{<br /> public enum ConfigFlag : uint<br /> {<br /> /// &lt;summary><br /> /// The configuration management service and the <br /> /// Configuration Service Providers (CSPs) process<br /> /// the input data.<br /> /// &lt;/summary><br /> Process = 1,<br /><br /> /// &lt;summary><br /> /// The configuration management service gathers <br /> /// and returns metadata for any XML parm elements <br /> /// it encounters.<br /> /// &lt;/summary><br /> Metadata = 2<br /> }<br /><br /> public class ConfigWrapper<br /> {<br /> [DllImport("aygshell.dll")]<br /> private extern static UInt32 DMProcessConfigXML( string xmlIn, UInt32 flag, out IntPtr xmlOutPtr );<br /><br /> [DllImport("coredll.dll")]<br /> private extern static IntPtr LocalFree( IntPtr hMem );<br /> <br /> public static string ProcessXml( string xml )<br /> {<br /> return ProcessXml( xml, ConfigFlag.Process );<br /> }<br /><br /> /// &lt;summary><br /> /// This function wraps acts as a managed interface to the <br /> /// DMProcessConfigXML in Pocket PC 2003+ and Smartphone 2002+<br /> /// The DMProcessConfigXML function grants remote access to the<br /> /// configuration management functionality of the mobile device. <br /> /// This function enables the submission of Extensible Markup <br /> /// Language (XML) information that causes the settings of a <br /> /// mobile device to change. See "Configuration Service Providers" <br /> /// in the API for details on the XML schema.<br /> /// &lt;/summary><br /> /// &lt;param name="xml"><br /> /// String of valid XML containing configuration data<br /> /// &lt;/param><br /> /// &lt;param name="flag"><br /> /// Action flag (see ConfigFlag for details)<br /> /// &lt;/param><br /> /// &lt;returns><br /> /// String of valid XML containing the result of this operation<br /> /// &lt;/returns><br /> public static string ProcessXml( string xml, ConfigFlag flag )<br /> {<br /> IntPtr xmlOutPtr;<br /> string xmlOutStr;<br /> long result;<br /><br /> result = DMProcessConfigXML( xml, (uint)flag, out xmlOutPtr );<br /> <br /> // marshal the output string<br /> xmlOutStr = Marshal.PtrToStringUni( xmlOutPtr );<br /><br /> // free the memory allocated by the API<br /> LocalFree( xmlOutPtr );<br /><br /> // throw an exception if an error code was returned<br /> if( result != 0 )<br /> {<br /> throw new ArgumentException( String.Format(<br /> "DMProcessConfigXML returned error code {0}", result ), <br /> xml );<br /> }<br /><br /> return xmlOutStr;<br /> }<br /> }<br />}Enjoy!

kcchesnut
11-17-2003, 11:09 PM
i didnt think .NETcf worked on SmartPhone 2002

Peter Foot
11-17-2003, 11:31 PM
i didnt think .NETcf worked on SmartPhone 2002

Yep thats right, it has the same DMProcessConfigXML function - but no .NETCF - this wrapper is only suitable for Windows Mobile 2003 devices.

BTW, useful bit of code Robert!

kcchesnut
11-17-2003, 11:53 PM
cool, i used it to do the standard BrowserFavorite demo.
Thanks for the code

Eric Roijen
12-08-2003, 03:21 PM
cool, i used it to do the standard BrowserFavorite demo.
Thanks for the code

Can you post some code on how to use thes functions?
Like the one you mention, the BrowserFavorite?

Thanks.
Eric.

ctitanic
04-07-2005, 06:36 PM
any VB .NET version of the code available.

ctitanic
04-07-2005, 07:57 PM
Imports System
Imports System.Runtime.InteropServices

Namespace DeviceConfigLib

Public Enum ConfigFlag As Integer
Process = 1
Metadata = 2
End Enum

Public Class ConfigWrapper

&lt;DllImport("aygshell.dll")> Private Function DMProcessConfigXML(ByVal xmlIn As String, ByVal flag As Integer, ByVal xmlOutPtr As IntPtr) As Integer
End Function

&lt;DllImport("coredll.dll")> Private Function LocalFree(ByVal hMem As IntPtr) As IntPtr
End Function

Public Function ProcessXml(ByVal xml As String) As String
Return ProcessXml(xml, ConfigFlag.Process)
End Function

' &lt;summary>
' This function wraps acts as a managed interface to the
' DMProcessConfigXML in Pocket PC 2003+ and Smartphone 2002+
' The DMProcessConfigXML function grants remote access to the
' configuration management functionality of the mobile device.
' This function enables the submission of Extensible Markup
' Language (XML) information that causes the settings of a
' mobile device to change. See "Configuration Service Providers"
' in the API for details on the XML schema.
' &lt;/summary>
' &lt;param name="xml">
' String of valid XML containing configuration data
' &lt;/param>
' &lt;param name="flag">
' Action flag (see ConfigFlag for details)
' &lt;/param>
' &lt;returns>
' String of valid XML containing the result of this operation
' &lt;/returns>
Public Function ProcessXml(ByVal xml As String, ByVal flag As ConfigFlag) As String

Dim xmlOutPtr As IntPtr
Dim xmlOutStr As String
Dim result As Integer

result = DMProcessConfigXML(xml, CType(flag, Integer), xmlOutPtr)

' marshal the output string
xmlOutStr = Marshal.PtrToStringUni(xmlOutPtr)

' free the memory allocated by the API
LocalFree(xmlOutPtr)

' throw an exception if an error code was returned
If (result &lt;> 0) Then
Throw New ArgumentException(String.Format("DMProcessConfigXML returned error code {0}", result), xml)
End If

Return xmlOutStr
End Function
End Class
end namespace


this is giving an error.

ctitanic
04-07-2005, 09:31 PM
disregard my previous post, we got it working.

Mike Temporale
04-08-2005, 01:07 AM
disregard my previous post, we got it working.

Cool. Glad we could help, kind of.... :wink: :lol:

rsuresh
07-29-2005, 05:14 PM
Hi All,
I was trying to use Roberts code to change the smartphone ringtone to vibrate? However, It returns the error don't think it likes my XML string statement.

The following is the exeception Visual Studio.nET returns:
$exception {"DMLProcessConfig.XML returned error code2147753993" }System.ArgumentException

My code is as follows


namespace MyProject
{
class Application
{
public static void Main()
{
string temp;
string xmlQuery
="&lt;wapprovisioningdoc>"+
"&lt;characteristic type=\"Sounds\">"+
"&lt;characteristic type=\"HKCU\\ControlPanel\\Sounds\\Ringtone0\">"+
"&lt;parm name=\"Sound\" value=av3w3r/>"+
"&lt;/characteristic>"+
"&lt;/characteristic>"+
"&lt;/wap-provisioningdoc>";


temp=ConfigWrapper.ProcessXml(xmlQuery);
MessageBox.Show(temp);


}//end main
}//end class application
}//end namespace myproject


Please tell me i'm doing something fudmentally wrong.

Also as an aside could someone please post an emaple showing how to query the metatags using the Config wrapper.

Cheers

Ro