Archive for 2007

ARANZ Medical presentation

Saturday, November 17th, 2007

On Thursday I did an internal presentation for the company I work for and it’s related siblings under the ARANZ umbrella.

The presentation introduced the Windows Mobile platform used by ARANZ Medical Limited to some of the other groups within ARANZ which do not have a mobile (or even Microsoft orientated) development focus. It also highlighted some of the themes I picked up upon while attending MEDC 2007 earlier this year, with an emphasis on those that had relevance to our medical products.

I thought some of you might be interested in the slides, so have made these available via slideshare.net.

How to run an application immediately after installation

Thursday, November 15th, 2007

It is quite common for commercial software to have a registration or configuration process which must be completed immediately after installation in order for the software to become operational. This blog entry outlines one technique for getting such a process to automatically occur after installation of a Windows Mobile software package.

My solution is largely based upon a sample application provided with the Windows Mobile 5.0 and Windows Mobile 6 SDKs. If you haven’t found these samples yet (installed by default) I encourage you to investigate them further.

Solution Overview
Most Windows Mobile Software is installed via CAB files. A CAB file is an archive which installs a number of files and registry settings onto a PDA. A less commonly used feature of a CAB file is that of a setup dll. A setup dll (traditionally named setup.dll) is a DLL which can hook into various steps of the installation/uninstallation process in order to extend or modify the process. The process of using a setup dll is described within MSDN in an article titled “Optional Setup.dll Files for installation“.

When the device processes a CAB file that includes a setup dll, it extracts the DLL and calls specifically named functions within it at the following stages of the installation process:

Since the DLL must export a set of functions it typically must be implemented in a native language such as C or C++. The functions exported by the setup.dll can perform any task they want and can optionally decide to abort the installation process.

So in order to run an application after installation of a CAB file, one approach is to write a setup dll that implements an Install_Exit() function that launches the newly installed executable.

Launching an application on installation
Since we want to perform a custom action in response to the installation process completing the correct place to place our custom code is the Install_Exit entry point.

One of the parameters to this entry point (as described in MSDN) is pszInstallDir which contains the path to the location the user has decided to install the application in (i.e. typically \Storage Card\Program Files\xyz or \Program Files\xyz). This will help us locate the executable that has been installed.

We can start the desired application by using the CreateProcess API. If we fail to launch the application we can return codeINSTALL_EXIT_UNINSTALL which will cause the CAB installation process to rollback any changes made during installation and display an error message to the user.

My sample application launches an application after installation by placing the following code within the Install_Exit function:

// We are provided with the installation folder the 
// user has installed the application into. So append
// the name of the application we want to launch. 
PROCESS_INFORMATION pi;
TCHAR szPath[MAX_PATH]; 
_tcscpy(szPath, pszInstallDir); 
_tcscat(szPath, _T("\\")); 
_tcscat(szPath, _T("TestApplication.exe")); 
 
// Start the application, and don't wait for it to exit 
if (!CreateProcess(szPath, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, &pi)) 
{ 
  // Failed to launch executable so indicate an error
  // and cause wceload to rollback the installation
  cie = codeINSTALL_EXIT_UNINSTALL; 
}

You will notice that this code sample hardcodes the name of the executable to launch (TestApplication.exe). It does however cope with users deciding to install the application on to an SD Card etc.

Using Visual Studio Smart Device CAB projects
ce-setup-dll-selected.pngce-setup-dll.pngHaving developed your custom setup.dll implementation you must package it into the CAB file in a particular way to indicate to the installation process that the file should be treated specially.

If you are using the Smart Device CAB project type within Visual Studio this is a two step process.

The first step is to add the “Primary Output” of your setup.dll project into the application folder of your setup project (use the file system viewer). This ensures that your dll is archived as part of the CAB file.

The second step is to indicate to the CAB building process which dll within your CAB file should be treated as the special “setup.dll”. To indicate which dll you want to use as the setup.dll within Solution Explorer you should select your Smart Device CAB project, and then switch to the Property viewer. You will notice one of the CAB file properties is called “CE Setup DLL”. Using a popup dialog that appears when this property is selected you should be able to navigate to the DLL you included in the first step of the process.

If you are creating your CAB file via a manually written INF file you specify the DLL that should be used by specifying a CESetupDLL parameter in your [DefaultInstall] section (documented within MSDN) as shown below:

[DefaultInstall]
CopyFiles = CopyToInstallDir,CopyToWindows
CESetupDLL = MySetup.dll

Sample Application

[Download sample application - 19.3Kb]

I have produced a small sample application which demonstrates this technique. It consists of a solution (SetupDLL.sln) that contains the following projects.

  • TestApplication – An application (written in C#) to run after the installation process.
  • SetupDLL – The DLL the CAB installation process invokes during installation in order to execute TestApplication.
  • SetupDLLCab – The CAB file project that packages everything up into a single CAB file for the end user to install.

If you build the example CAB file and then install it on a device you should notice that at the end of the installation process (just before the “installation has completed” message box appears) the included .NET Compact Framework application will automatically run.

I will end this blog posting with a question. Is anyone interested in being able to write such setup dlls within a managed language such as VB.NET or C#, and if so what kind of custom behaviour/logic would you be interested in implementing?

Windows Mobile Tip: Show all files within File Explorer

Thursday, November 15th, 2007

show-all-files.PNGThis is a Windows Mobile Pocket PC specific tip which takes some people a little while to discover (especially if using a Windows Mobile device isn’t part of their day to day job).

By default the File Explorer application does not show all files. As well as files specifically marked as hidden, it will hide files with a series of “special” file extensions such as *.dll.

In order to show these files you must enable the “Show All Files” option, which can be achieved by following these steps:

  1. Open the File Explorer application.
  2. Scroll down to the blank area at the bottom of a directory listing.
  3. Tap and hold the stylus on the blank space underneath the last file in the directory listing.
  4. Select “show all files” from the popup menu which appears.

The directory listing should now display all files within the folder. Unfourtantly since file extensions are not visible you may end up with multiple enteries with the same name. For example, foo.exe, foo.dll, foo.txt and foo.pdf will all be listed as “foo”.

If the icon associated with a particular file extension doesn’t help you determine the type of file, you can tap on the file. If the file is assoicated with an application it should be launched automatically. If there is no association a message box will be displayed stating “foo.xyz is not a valid executable”. This message box will display the full filename (including extension) of the file.

A future blog entry will outline how developers can extend the functionality of built in applications such as File Explorer. We will develop an extension that allows us to rename the file extension of a file (i.e. change foo.log into foo.txt).

Code Camp Boot Camp summary

Wednesday, November 7th, 2007

Sponsors of Code Camp Boot CampIt’s now a couple of days since Code Camp Boot Camp finished, and I finally have some time to summarise the event, having completed my last university exam (ever?) earlier today.

This was the first .NET code camp event I have been directly involved in organising. Peter Jones and Simeon Pilgrim have already posted some good summary posts on the event.

Overall the general consensus was that the event was a great success.

It was good to see encouraging comments on the catering for the event, since this was my primary responsibility and my first time performing such a task. Subway sandwiches seemed to go down a treat.

Unfortunately helping to organise the event I didn’t get to see all the presentations I would have liked to. The ones that I did see were just as good as those at “professional” events such as MEDC which cost significantly more to attend. We are lucky to have a number of excellent speakers in New Zealand, who don’t mind travelling at their own expense to events around the country, and this generosity is a large part of why we can make such events free for attendees.

Over all I came away with a better appreciation of LINQ, and in particular technologies around LINQ and SQL (such as SQL to LINQ and ADO.NET Entities). I liked the ASP.NET Dynamic Data Controls presentation by Andrew Tokeley and can see some personal projects where this could be a useful framework.

The Morse Code puzzle challenge only had a couple of entries but as Simeon mentioned the 4 solutions we obtained had taken quite different approaches to solving the problem. I was quite impressed by the solution of Simon Green (who was the eventual winner of the Zune MP3 player). Simon had solved the problem not once, but twice, and his LINQ based solution was just a tad slower than Simeon’s hand coded radix tree based model solution.

Personally I found the event a great way to develop some personal contacts and future opportunities. Hopefully I’ll be presenting at the Southland .NET User Group and a yet to be formed Mobile and Embedded Developers User Group as a result of conversations I had at the event.

I would like to take the oppertunity to thank the sponsors who really made this the event that it was…

We out these sponsors the event wouldn’t have been possible.

Vodafone v1210 Windows Mobile 6 ROM upgrade

Tuesday, November 6th, 2007

I went hunting for the Windows Mobile 6 ROM upgrade a couple of times since I purchased a Vodafone v1210 smartphone earlier this year and saw an upgrade was planned for later in the year by Vodafone New Zealand.

It’s probably been out for quite a while and I’m the last one to find it… but today I found the official Vodafone New Zealand ROM upgrade so thought I would share the link.

http://www.vodafone.co.nz/personal/help/device-support/vodafone/vodafone_1210/

Code Camp Boot Camp later today!

Friday, November 2nd, 2007

Code Camp Boot Camp shirt and dog tagsI have just got back from a speakers dinner held for the speakers who are speaking at the Code Camp Boot Camp event happening in Christchurch later today (I must be there in under 7 hours time in fact…)

The event promises to be a great series of exciting presentations by some really skilled developers. Even if you haven’t registered or can’t spare the entire weekend, it would be worth your while comming along to atleast a session or two and you’re more than welcome to do this.

This has been the first .NET User Group event I have helped organise, and hopefully it isn’t the last as it’s been loads of fun. If you’re at this event please do say hi, it would be great to put a face to some of the people I’ve only met online.

Portable Puzzle Collection beta 2 (plus source code)

Wednesday, October 31st, 2007

OpenNETCF logoToday I produced a build of my port of Simon Tatham’s Portable Puzzle Collection as my submission to OpenNETCF’s latest monthly coding competition. While producing this submission I realised that since the last mention of this porting effort I hadn’t provided an update on my progress, or even outlined how you could obtain the source code. Opps…

Since the last blog entry I have created a project on google code to host my porting efforts. You can find this project at http://code.google.com/p/portablepuzzlecollection-wm.

If you are interested in helping out with this porting effort, here are some details you will probably need to know:

Tools required:
In order to build the puzzle collection you will need to have the following tools installed on your desktop machine.

Build instructions:
Unlike many projects which use Visual Studio 2005, this port does not have a project or solution file. Instead the Visual Studio 2005 compilers are used from the command line as part of a custom build framework developed by Simon Tatham. This is mainly due to the build framework also supporting building the puzzles for Mac OS X, desktop Windows and Linux all from a Unix based build server.

I have modified the build script with some temporary hacks to allow building the puzzle collection with Visual Studio 2005 on a Windows based host. To build the puzzle collection in this environment you should perform the following steps:

  • Obtain the source code from the SVN Repository.
  • Open up a command prompt.
  • Change to the directory you placed the source code in.
  • run build-ppc.bat.

Assuming no errors this should produce a CAB file and a setup.exe. If an error occurs you may be able to determine what happened by viewing the contents of the wce-build-log.txt file.

To install the software manually install the CAB file on your device, or run the setup.exe executable on your desktop PC (which will automatically download and install the CAB file for you).

Depending upon your circumstances you may need to alter some of the paths specified within build-ppc.bat. Eventually I may produce a VS2005 project file as an alternative (and more friendly) way to build the puzzle collection.

Found an issue with this port?
There are still a number of issues outstanding with this port. If you find any I would appreciate it if you could report them via the issue tracker available at http://code.google.com/p/portablepuzzlecollection-wm/issues/list. Or even better submit a patch!

Apart from a few cosmetic style issues, the major issues I am aware of at present is the lack of keypad support for some games. This is stopping some of the games from being playable on a Smartphone (Windows Mobile Standard) device.

MCTS welcome kits arrive

Wednesday, October 31st, 2007

MCTS: Windows Mobile 5.0 Application Development logo

Last week I received a package from Microsoft Singapore. It was my charter member certificate for the MCTS: Windows Mobile 5.0 Application Development certification. I sat the beta exam for this about 12 months ago, so it was good to finally receive the certificate, even if it was only a token piece of paper (the real value in certification lies elsewhere).

The interesting thing is that yesterday I also received a mass email sent out by Lutz Ziob, General Manager for Microsoft Learning. Due to the delays in shipping (some) welcome kits over the last few months Microsoft decided to provide each affected MCP with a free exam voucher.

I’ll probably use my free voucher to sit the 70-500: Windows Mobile Designing, Implementing, and Managing exam later this year, or should I hold out for the Windows Mobile 6 and/or Windows Embedded CE exams? I wonder how long it will be before these become available?

I was surprised when I looked on the MCP website that there are only 107 MCTS: Windows Mobile 5.0 Application Development certification holders as of October 2nd 2007.

Capture and respond to user input to a notification bubble

Tuesday, October 30th, 2007

A popup notification showing an HTML based form for ordering a Pizza.In my previous blog entry about notifications I mentioned that we had not covered the ResponseSubmitted event. Subscribing to this event allows you to respond to user input entered within a notification bubble. This blog entry discusses how you can capture and process user input within notifications.

Creating an HTML based form
The contents of a notification bubble is formatted using HTML. To request user input within a notification bubble we can utilise a HTML based form.

A simple form specified within HTML may look like the following example:

<form>
  Name: <input name="name" /><br />
  <input type="submit" />
</form>

Similar to a System.Windows.Forms base application there are a range of controls which can be used within an HTML based form. These controls are typically specified via an <input /> element, although there are some exceptions as shown in the following table:

Name HTML Syntax
Hidden Field
<input type="hidden" name="fieldname" value="default" />
Textbox (single line)
<input type="text" name="fieldname" value="default" />
Textbox (single line password)
<input type="password" name="fieldname" value="default" />
Textbox (multi line)
<textarea name="fieldname" cols="40" rows="5">
    default value
</textarea>
Radio buttons
<input type="radio" name="fieldname" value="1" />
<input type="radio" name="fieldname" value="2" />
<input type="radio" name="fieldname" value="3" />
Checkbox
<input type="check" name="fieldname" checked="true" />
Combobox
<select name="fieldname">
    <option value="1">option 1</option>
    <option value="2">option 2</option>
    <option value="3">option 3</option>
</select>

A sample form with two textbox controls could be specified within C# source code as follows:

Notification notif = new Notification();
notif.Text = @"<form>
    Field 1: <input type=""text"" name=""fieldname1"" /><br />
    Field 2: <input type=""text"" name=""fieldname2"" />
  </form>";

Buttons
Using the controls specified above allows a notification to accept input from the user. However it does not provide the user with a mechanism to submit a completed form to the application for further processing.

A form is typically submitted when the user presses a submit button. A submit button can be specified within HTML via the use of an <input type=”submit” /> element. Whenever the user presses the submit button the ResponseSubmitted event will be triggered, allowing the form to be processed by the application.

Buttons can also be utilised within a notification to temporarily hide or permanently close a notification without submitting a form (useful for cancel or postpone style buttons etc). These actions can be specified via the use of button elements within the HTML as demonstrated below:

<!-- This button will minimise the notification -->
<input type="button" name="cmd:2" value="Hide" />
 
<!-- This button will permanently close the notification -->
<input type="button" name="something" value="Close" />

The value attribute contains the text displayed on the button, while the name (i.e. “cmd:2″) controls the action which occurs when the button is pressed. The name “cmd:2″ is a special value indicating to the operating system that the notification should be minimised and displayed as an icon that can be clicked to redisplay the notification. Having a button with any other name will cause the notification to permiantly be dismissed without the ResponseSubmitted event firing. All other “cmd:n” style button names are reserved by Microsoft for future use.

Hyperlinks
A HTML form can also contain traditional hyperlinks such as the following example:

<a href="help">Display further help</a>

Whenever such a link is pressed within the notification, the ResponseSubmitted event will trigger and the response string will be the string specified as the href attribute (”help” in this example).

Many of the built in operating system notifications utilise hyperlinks to provide access to settings or customisation dialogs.

Processing the response
When a HTML form within a notification is submitted the ResponseSubmitted event will trigger and this is the ideal opportunity for an application to process the contents of a form. The ResponseEventArgs parameter passed to this event handler contains a Response property that includes the current values of all fields within the form encoded in a format known as application/x-www-form-urlencoded.

Section 17.13.4 of the HTML 4.01 standard discusses application/x-www-form-urlencoded form data with the following description of the encoding process.

This is the default content type. Forms submitted with this content type must be encoded as follows:

  • Control names and values are escaped. Space characters are replaced by `+’, and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH’, a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as “CR LF” pairs (i.e., `%0D%0A’).
  • The control names/values are listed in the order they appear in the document. The name is separated from the value by `=’ and name/value pairs are separated from each other by `&’.

As an example, if the form specified above contained the strings “Hello World” and “Good Bye” it would be encoded and appear within the Response property as follows:

?fieldname1=Hello+World&fieldname2=Good+Bye

The Microsoft documentation for the Response property contains an example of how to parse such response strings. It does this via some rather brittle string search and replace style operations. The sample code is not very generic, as it will break if you change the structure of your form even a little (such as renaming a field) and it does not deal with decoding hex escaped characters.

Within the sample application mentioned below I have implemented a function called ParseQueryString which performs the application/x-www-form-urlencoded decode process and returns a more easily used Dictionary of field control names to value mappings. This allows you to write a ResponseSubmitted event handler which looks something like the following:

private void notification1_ResponseSubmitted(object sender,
    ResponseSubmittedEventArgs e) 
{ 
  // This dictionary contains a mapping between 
  // field names and field values. 
  Dictionary<string, string> controls = ParseQueryString(e.Response); 
 
  // Make use of the field values, in this case pulling the
  // values out of the textboxes and displaying a message
  // box.
  MessageBox.Show(String.Format("first field = {0}, second field = {1}", 
	controls["fieldname1"], controls["fieldname2"]); 
}

This should make the intention of the ResponseSubmitted event handler easier to determine, and makes for more easily maintained code. The “hard” part of the response parsing logic is now hidden away within the ParseQueryString function, leaving you with an easy to use collection of field values to play with.

Including images within a notification
Sometimes it is helpful to include a small image within a popup notification. This is possible, but as Keni Barwick found out, the syntax of your HTML has to be fairly precise for the notification balloon to locate the image (a similar situation to images within HTML help files).

You should have good success if you use the file:// protocol, and include a full path to your image using backward slashes to separate directories, i.e. use the format:

<img src="file:///path/to/image.bmp" />

For example to include the image \windows\alarm.bmp you would use the following HTML:

<img src="file:///windows/alarm.bmp" />

You could hard-code the path to your image file but this could cause problems if the user decides to install your application in a different location (on an SD card for example). If your images are stored in the same folder as your main executable you can determine the path to your images at runtime by using a function similar to the following code snippet:

using System.Reflection; 
using System.IO;
 
public string GetPathToImage(string fileName)
{
  // Determine the exe filename and path
  Assembly assembly = Assembly.GetExecutingAssembly();
  string executablePath = assembly.GetName().CodeBase;
 
  // Trim off the exe filename from the path
  executablePath = Path.GetDirectoryName(executablePath);
 
  // Add the specified filename to the path
  return Path.Combine(executablePath, fileName);
}
 
string imageURL = GetPathToImage("foo.bmp");

Sample Application

[Download notificationuserresponsesample.zip - 16KB]

A sample application is available for download. The sample demonstrates using a notification to specify the details of a pizza order. It also demonstrates the inclusion of an image within a notification.

When targeting a Windows Mobile 5.0 or above device, you could extend the sample by using the custom soft keys feature mentioned in a previous blog entry to submit the notification by pressing a subkey instead of pressing a button within the body of the notification.

Please feel free to make use of the ParseQueryString method and any associated functionality within your own applications.

Neat custom controls, comming your way soon…

Tuesday, October 9th, 2007

For the past few days I have been working on a University assignment due Monday, as well as helping organise the next .NET User Group Code Camp being ran on November the 3rd and 4th. As such progress has been slow on my personal projects.

As mentioned earlier I have started work on improving my .NET Compact Framework Notification wrapper to support arbitrarily complex soft key menus. Progress has been quite good, with custom menus now largely working. Along the way however I have learnt a number of interesting things about the implementation of SHAddNotification (and SHCreateMenuBar). I’ll discuss some of these later and their impact on the wrapper, which hopefully I will be able to complete once my assignment is submitted.

Another project I have toyed with this week is porting SWI-Prolog’s text console window (plterm.dll) to Windows Mobile as part of improving the editor window within PythonCE. Rainer Keuchel has ported an older version of SWI-Prolog, so I took the source code for the latest version of SWI-Prolog and applied a similar set of changes. Initial progress looks good, the console widget has really been designed for easy reuse in other applications. I might even try to create a .NET Compact Framework wrapper for it, as being able to chuck up a text prompt can be a handy debugging interface at times.

Today I also noticed that João Paulo Figueira has provided an initial demonstration of a list-based form control library he has been working on. This library for native C++ developers is designed to give a user interface similar to the Pocket Outlook UI seen on Pocket PC devices. I took his code and compiled it for Windows Mobile 6 Standard edition (i.e. a smartphone). It seems with a little work this control could also work on smartphones. The main issues were reasonably minor ones such as lack of support for using the keypad to interact with some of the controls, which look like they would be reasonably easy to resolve.