
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Johan de Koning &#187; Research</title>
	<atom:link href="http://www.johandekoning.nl/index.php/category/research/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johandekoning.nl</link>
	<description>www.johandekoning.nl</description>
	<lastBuildDate>Mon, 09 Jan 2012 09:21:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Command-line arguments Windows Mobile</title>
		<link>http://www.johandekoning.nl/index.php/2008/08/04/command-line-arguments-windows-mobile/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=command-line-arguments-windows-mobile</link>
		<comments>http://www.johandekoning.nl/index.php/2008/08/04/command-line-arguments-windows-mobile/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 20:57:38 +0000</pubDate>
		<dc:creator>Johan de Koning</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Software development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Command-line]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://www.johandekoning.nl/?p=68</guid>
		<description><![CDATA[In September I will go on holiday to the United States for 3 weeks. It would be nice to send updates to family and friends by placing images on Picasa. These web images will be taken with the photocamera from my mobile (which is Windows Mobile 6 based). I will upload the pictures when a [...]]]></description>
			<content:encoded><![CDATA[<p>In September I will go on holiday to the United States for 3 weeks. It would be nice to send updates to family and friends by placing images on Picasa. These web images will be taken with the photocamera from my mobile (which is Windows Mobile 6 based). I will upload the pictures when a free WiFi access point is available.</p>
<p>The program will place taken photos in a queue. When I have an internet connection available I can upload all the pictures from this queue to Picasa. This results in an application that can be seperated in two parts: the take a photo functionality and the upload photo-queue functionality.</p>
<h3>Use cases explaining functionality</h3>
<p>My mobile has a photo camera button which will trigger the default photo camera application. This default camera application can be replaced by changing the button settings on the mobile phone. When replaced (and when clicking the camera button) I want my application to start up ready to take a picture (so it will behave the same as the default camera application). After taking a picture you can type in some comment and add it to the queue.</p>
<p>When arriving at the hotel (or some other connective place) I want to upload the taken images. I can off course push the photo camera button again, but this time it is not my intention to take a new picture. In this case I want to start the application from the Start -&gt; Programs menu and see the state of the queue with the option to upload the photos. The same application but with a different startup state.</p>
<p>The use of command-line arguments should solve this problem. But is this also possible with the Compact .Net Framework</p>
<h3>Not a solution: Environment.GetCommandLineArgs</h3>
<p>For Windows Form based application (which my mobile application is) the use of the <a href="http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs.aspx">Environment </a>class is suggested to get the command-line arguments. The static method</p>
<pre class="brush: csharp; title: ; notranslate">&lt;br /&gt;
public static string[] GetCommandLineArgs()&lt;br /&gt;
</pre>
<p>
The problem is that this method is not implemented inside the .Net Compact Framework and can&#8217;t therefore not been used.</p>
<h3>Solution: static void Main(String[] args)</h3>
<p>Just like console application (written in .Net) you have a Main method for your Windows Forms application. Besides the files created for the Form (by default Form1.cs and Form1.Designer.cs) a Program.cs file is created which contains a Main method. By adding a <em>String[] args</em> to the Main method, you can work with command-line arguments. An example of the new Main method</p>
<p>
<pre class="brush: csharp; title: ; notranslate">&lt;br /&gt;
[MTAThread]&lt;br /&gt;
static void Main(String[] args)&lt;br /&gt;
   {&lt;br /&gt;
      if (args != null &amp;#038;&amp;#038; args.Length &gt; 0)&lt;br /&gt;
     {&lt;br /&gt;
         foreach (String arg in args)&lt;br /&gt;
         {&lt;br /&gt;
            MessageBox.Show(arg);&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     else&lt;br /&gt;
     {&lt;br /&gt;
         MessageBox.Show(&quot;No program arguments&quot;);&lt;br /&gt;
     }&lt;br /&gt;
     Application.Run(new Form1());&lt;br /&gt;
}&lt;br /&gt;
</pre>
</p>
<p>The arguments can be given to the form (Form1 in this example) by changing the constructor.</p>
<h3>Creating a shortcut</h3>
<p>The easiest way to create a shortcut is by using the Windows Explorer on your mobile phone. Navigate to the executable file of the application. Tap and hold the file selected with your styles to get the context menu. Select copy. </p>
<p>At the same location (or on a different location) tap (and hold) on an empty space to get the context menu. This context menu will give you the option to paste as a shortcut. </p>
<p>To add the command line argument inside the shortcut, i copied the shortcut (.lnk file) with ActiveSync to my desktop pc and edit the content with notepad. The file will now look like this:</p>
<p><em>59#&#8221;\Programmabestanden\ProgramArguments\ProgramArguments.exe&#8221; this_is_a_program_argument</em> </p>
<p>My Windows Mobile OS is Dutch. On an English based OS the Programmabestanden part will be replaced by something like Program files. I don&#8217;t know if the number 59 before the line is mandatory. The number of characters with quotes is 59 long. So maybe it is used for reading optimalization. I really don&#8217;t know. I just added the this_is_a_program_argument at the end of the shortcut, saved the file and copied it back to my pocket pc. </p>
<p>Starting the application with the shortcut will show a messagebox with the text this_is_a_program_argument. When starting the application from the normal executable you will get a messagebox saving No program arguments.</p>
<h3>Attachment: example project</h3>
<p>You can download the example application from <a href="http://www.johandekoning.nl/projects/programarguments.zip">here</a></p>
<h3>Special thanks</h3>
<p>I want to thank <a href="http://www.pauldendulk.com">Paul</a> for discussing this problem and finding a solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandekoning.nl/index.php/2008/08/04/command-line-arguments-windows-mobile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

