Monday, November 17, 2003
Device Configuration Using .NET CF
Posted by Robert Levy in "DEVELOPER" @ 02: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.Runtime.InteropServices;
namespace DeviceConfigLib
{
public enum ConfigFlag : uint
{
/// <summary>
/// The configuration management service and the
/// Configuration Service Providers (CSPs) process
/// the input data.
/// </summary>
Process = 1,
/// <summary>
/// The configuration management service gathers
/// and returns metadata for any XML parm elements
/// it encounters.
/// </summary>
Metadata = 2
}
public class ConfigWrapper
{
[DllImport("aygshell.dll")]
private extern static UInt32 DMProcessConfigXML( string xmlIn, UInt32 flag, out IntPtr xmlOutPtr );
[DllImport("coredll.dll")]
private extern static IntPtr LocalFree( IntPtr hMem );
public static string ProcessXml( string xml )
{
return ProcessXml( xml, ConfigFlag.Process );
}
/// <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.
/// </summary>
/// <param name="xml">
/// String of valid XML containing configuration data
/// </param>
/// <param name="flag">
/// Action flag (see ConfigFlag for details)
/// </param>
/// <returns>
/// String of valid XML containing the result of this operation
/// </returns>
public static string ProcessXml( string xml, ConfigFlag flag )
{
IntPtr xmlOutPtr;
string xmlOutStr;
long result;
result = DMProcessConfigXML( xml, (uint)flag, out 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 != 0 )
{
throw new ArgumentException( String.Format(
"DMProcessConfigXML returned error code {0}", result ),
xml );
}
return xmlOutStr;
}
}
}[/code]Enjoy!
namespace DeviceConfigLib
{
public enum ConfigFlag : uint
{
/// <summary>
/// The configuration management service and the
/// Configuration Service Providers (CSPs) process
/// the input data.
/// </summary>
Process = 1,
/// <summary>
/// The configuration management service gathers
/// and returns metadata for any XML parm elements
/// it encounters.
/// </summary>
Metadata = 2
}
public class ConfigWrapper
{
[DllImport("aygshell.dll")]
private extern static UInt32 DMProcessConfigXML( string xmlIn, UInt32 flag, out IntPtr xmlOutPtr );
[DllImport("coredll.dll")]
private extern static IntPtr LocalFree( IntPtr hMem );
public static string ProcessXml( string xml )
{
return ProcessXml( xml, ConfigFlag.Process );
}
/// <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.
/// </summary>
/// <param name="xml">
/// String of valid XML containing configuration data
/// </param>
/// <param name="flag">
/// Action flag (see ConfigFlag for details)
/// </param>
/// <returns>
/// String of valid XML containing the result of this operation
/// </returns>
public static string ProcessXml( string xml, ConfigFlag flag )
{
IntPtr xmlOutPtr;
string xmlOutStr;
long result;
result = DMProcessConfigXML( xml, (uint)flag, out 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 != 0 )
{
throw new ArgumentException( String.Format(
"DMProcessConfigXML returned error code {0}", result ),
xml );
}
return xmlOutStr;
}
}
}[/code]Enjoy!
- Discuss [9 replies]
- Permalink