Smartphone Thoughts - Daily News, Views, Rants and Raves

Be sure to register in our forums! Share your opinions, help others, and enter our contests.





Go Back   Thoughts Media Forums > SMARTPHONE THOUGHTS > Smartphone Developer

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 11-17-2003, 10:04 PM
Philosopher
Join Date: Jun 2003
Posts: 593
Default Device Configuration Using .NET CF

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.
Code:
using System;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;		}	}}
Enjoy!
__________________
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Reply With Quote
  #2 (permalink)  
Old 11-17-2003, 11:09 PM
Pupil
Join Date: Sep 2003
Posts: 25

i didnt think .NETcf worked on SmartPhone 2002
 
Reply With Quote
  #3 (permalink)  
Old 11-17-2003, 11:31 PM
Thinker
Join Date: Apr 2007
Posts: 368

Quote:
Originally Posted by kcchesnut
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!
 
Reply With Quote
  #4 (permalink)  
Old 11-17-2003, 11:53 PM
Pupil
Join Date: Sep 2003
Posts: 25

cool, i used it to do the standard BrowserFavorite demo.
Thanks for the code
 
Reply With Quote
  #5 (permalink)  
Old 12-08-2003, 03:21 PM
Neophyte
Join Date: Nov 2003
Posts: 1

Quote:
Originally Posted by kcchesnut
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.
 
Reply With Quote
  #6 (permalink)  
Old 04-07-2005, 06:36 PM
Oracle
ctitanic's Avatar
Join Date: Mar 2005
Posts: 1,001

any VB .NET version of the code available.
__________________
Ctitanic
http://www.tweaks2k2.com
 
Reply With Quote
  #7 (permalink)  
Old 04-07-2005, 07:57 PM
Oracle
ctitanic's Avatar
Join Date: Mar 2005
Posts: 1,001

Code:
Imports System
Imports System.Runtime.InteropServices

Namespace DeviceConfigLib

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

    Public Class ConfigWrapper

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

        <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

        ' <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 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 <> 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
http://www.tweaks2k2.com
 
Reply With Quote
  #8 (permalink)  
Old 04-07-2005, 09:31 PM
Oracle
ctitanic's Avatar
Join Date: Mar 2005
Posts: 1,001

disregard my previous post, we got it working.
__________________
Ctitanic
http://www.tweaks2k2.com
 
Reply With Quote
  #9 (permalink)  
Old 04-08-2005, 01:07 AM
Editor Emeritus
Mike Temporale's Avatar
Join Date: Aug 2006
Posts: 11,180

Quote:
Originally Posted by ctitanic
disregard my previous post, we got it working.
Cool. Glad we could help, kind of.... :wink: :lol:
__________________
"I have no special talents, I am only passionately curious" - Albert Einstein
 
Reply With Quote
  #10 (permalink)  
Old 07-29-2005, 05:14 PM
Neophyte
Join Date: Jul 2005
Posts: 3
Default can someone tell me whats wrong with my code?

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

Code:
namespace MyProject
{
	class Application
	{
		public static void Main()
		{
			string temp;
			string xmlQuery
                                  ="<wapprovisioningdoc>"+
		             "<characteristic type=\"Sounds\">"+
                             "<characteristic type=\"HKCU\\ControlPanel\\Sounds\\Ringtone0\">"+
                             "<parm name=\"Sound\" value=av3w3r/>"+ 
                             "</characteristic>"+
                             "</characteristic>"+
                             "</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
 
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://forums.thoughtsmedia.com/f95/device-configuration-using-net-cf-12659.html
Posted By For Type Date
Smartphone Thoughts: Device Configuration Using .NET CF This thread Refback 07-10-2008 06:20 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Plugged In with the Samsung i320 Smartphone Mike Temporale Smartphone Hardware 17 12-13-2006 03:50 PM
Goodbye ActiveSync, Hello Windows Mobile Device Center Kris Kumar Smartphone Software 39 10-07-2006 07:29 PM
Inside Windows Vista: Windows Mobile Device Center and Sync Center Kris Kumar Smartphone Articles & Resources 28 06-21-2006 09:32 PM
Picking the Right Email Strategy for Your Windows Mobile Device Jason Dunn Smartphone Talk 12 09-15-2005 06:29 AM
Mobile DevCon 2004 San Francisco Jason Dunn Smartphone Events 1 04-07-2004 12:59 AM


All times are GMT +1. The time now is 07:43 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 RC7