## Archive for April, 2008

### Embedded .NET User Group: Meeting 1 – Summary

Friday, April 25th, 2008

On Tuesday the Christchurch Embedded .NET User Group (EDNUG) held its first meeting. A good turnout of over 20 people attended bringing with them a wide range of experience and interest levels in embedded development. It was good to see a few people getting their first exposure to embedded development!

Andrew Leckie, Bryn Lewis, and myself decided to kick off the user group with a general introduction to the various Microsoft technologies and platforms for embedded development. There was a lot of interest in the audience for the .NET Micro Framework and many questions around how extendable it was from a third party perspective. During the presentation Bryn raised many interesting examples of previous projects he has worked on, including GPS enabled versions of the game DOOM and Windows CE based telemetry systems for Trains.

In the end due to time constraints we split the presentation up into two sessions. With the second half to be presented at our next meeting. I have attached the slides from the first session which covered an introduction of the .NET Micro Framework, .NET Compact Framework, Windows Embedded CE and Windows Mobile below.

It was great to chat with many of you during the meeting. One thing that was discussed was the “SPARK Your Imagination” promotion and the possibility of organising a group shipment of development boards. If you would be interested, have any comments or are able to offer support to the user group, please don’t hesitate to contact me.

### SPARK your (Windows CE) Imagination

Thursday, April 17th, 2008

First announced with the release of Windows Embedded CE 6.0 R2 the SPARK initiative is designed to provide a source of cheap Windows CE development tools to hobbyists and other non commercial users such as academics.

As Mike Hall mentions in a recent blog entry the first development boards packages under this initiative are finally starting to become available. This announcement neatly dove tails into yesterday’s discussions about low cost development tools for Windows Mobile. In Mike Hall’s own words:

Windows CE has traditionally focused on professional embedded developers, sure we’ve had the evaluation kits for developers to try out the development tools and operating system, but these time out after 180 days, which is ok for commercial developers to make a decision about moving forward with a Windows CE based project but isn’t ideal for the community/academic/hobbyist developer.

The Spark Your Imagination program offers non-commercial developers low cost development boards (both X86 and ARM based options available) combined with fully licensed copies of Visual Studio 2005, and the latest release of Windows CE (i.e. Platform Builder) for essentially the cost of the hardware.

More details, including links to the available hardware options, can be found on the Spark Your Imagination website.

### Free Windows Mobile Development Tools?

Wednesday, April 16th, 2008

What tools do you use to develop your Windows Mobile applications? Today I received the following question:

I am looking to develop VB.NET applications for WM5, but I am on far too tight a budget to afford Visual Studio. Is there a way to use VS2008 Express for WM5 development, or is there another free way to do this?

How would you answer this question?

When I first started developing applications as a hobbyist for Palm OS (and then eventually Windows Mobile) I utilised free tools. Free (or at-least cheaply) available IDEs and compilers were a large factor in getting me started in this area of development that has now turned into a professional career. A lot of my friends got started in the same way and Dale Lane mentioned a similar scenario in his recent interview.

I am interested in discussing what tools hobbyists are currently utilising as they discover they can develop custom applications for their PDAs.

At present the main options for Windows Mobile development are most likely as follows:

• Embedded Visual C++ v4.0 – A free download that supports C and C++ development only. Doesn’t provide full support for newer versions of Windows Mobile and is fairly unsupported these days. A number of open source projects use this tool specifically because it’s a free download.
• Visual Studio 2005 Standard Edition (or above) – A non free IDE that supports native (C/C++) and managed (C#/VB.NET) development.
• Visual Studio 2008 Professional Edition (or above) – A non free IDE that supports native (C/C++) and managed (C#/VB.NET) development (adds support for .NET CF 3.5 development).

This means to develop a VB.NET application for a Windows Mobile PDA you require to purchase a copy of Visual Studio. The free Express editions of the IDE are not suitable.

If someone was interested in mucking around on an occasional Saturday afternoon and slowly learning about Windows Mobile development how would you suggest they go about it without occurring “significant” expense? I guess the 90 day trial version of Visual Studio 2008 Professional is possibly an option, but that does not leave too many weekends before the free license expires.

Is the lack of low cost development tools a problem? Are hobbyists an important part of the Windows Mobile ecosystem? What sort of developer would you classify yourself as? What helped you get started in programming PDA applications? Did you get started in your spare time or as part of your day job? Are there alternative development tools worth taking a look at?

### Windows Mobile Tip: ActiveSync Add/Remove Programs

Friday, April 11th, 2008

Are you aware of the Add/Remove Programs menu option within ActiveSync? When you have a PDA connected to your desktop PC you can use the dialog to install new applications onto your PDA as well as uninstall existing software.

For example when you install the .NET Compact Framework 3.5 Redistributable on your desktop PC it will register the .NET CF 3.5 CAB files with ActiveSync. This means you can install the .NET CF 3.5 on as many PDAs as you require by using the Add/Remove Programs dialog. You don’t need to re-install the redistributable package for each newly connected PDA.

With a little bit of additional effort it is possible for application developers to register their own application CAB file(s) with ActiveSync so that they are installable via the Add/Remove Programs dialog. This provides an easy way for non technical users to install your application as they do not need to be able to manually copy a file to the PDA or select it within File Explorer. You can even get this to occur automatically when your desktop setup application runs.

### Community Interview: Raffaele Limosani

Wednesday, April 9th, 2008

1) Can you tell us a little about yourself?

My name is Raffaele Limosani, I’m a Support Engineer at Microsoft CSS (Customer Service and Support) and I’m located in Milan, in the “Sunny” Italy — not so “sunny” btw compared to where I come from! (Rome) :-)

2) Can you tell us a little about what your role as a Support Engineer involves? What kind of developers do you help support?

I help ISV Application Developers “realize their potential” when working on the Windows Mobile and CE platforms: basically, if you have a Technical Support contract (including the one you got buying a Visual Studio box!) and need help while developing Smart Device projects, if you’re located in Europe-Middle East-Africa chances are that I’ll be your contact at Microsoft. I deal with “Premier” Customers (big contracts), Partners, MSDN Subscribers or developers who bought a Visual Studio box… are you aware that together with Visual Studio you bought Technical Support Incidents? Test us! :-)

3) You have recently started blogging about Windows Mobile development. What was your emphasis for doing this?

I felt that a blog was missing in the Windows Mobile-related blogosphere, related to Technical Support: that’s where the subtitle comes from… (”Support Side Story”) Basically I’m facing issues that for example didn’t find an answer in newsgroups and forums, or developers asking for advice about how to architect their applications. Sometimes I find myself repeating the usual suggestions (especially for .NET CF Memory Leaks or Kiosk-mode applications), and therefore I thought that a good investment for the community would be to publish my usual suggestions and solutions.

4) Your blog shows some real insightful glimpses into not only technical aspects of the Windows Mobile OS, but also how the Windows Mobile ecosystem is structured and functions. Would you mind briefly explaining the major players involved from the time Microsoft develops a new OS feature until the time the device reaches a shop or third party developer?

Microsoft provides device manufacturers (OEMs) with a tool called “Adaptation Kit for Windows Mobile” (a special edition of “Platform Builder”): this contains about 90% of the source-code for the Operating System and device driver sample source code. OEMs use this tool to adapt the Operating System to their hardware. They physically BUILD the platform after possibly having developed their own DRIVERS based on the samples that Microsoft provides. Apart from building the bits, it’s completely up to the OEMs to configure the OS, in terms of Security configuration, connections and so on (especially when a Mobile Operator brands the device). This is why it may happen that a problem is reproducible on one device and not another, with the same OS: in terms of Technical Support, many times the best initial step involves verifying if the issue is reproduced on the Emulators as well – if that’s true, it’s much easier for us to troubleshoot as we can also package a DEBUG build of the platform, or instrument parts of the RETAIL build with some specific debugging info. This is not available for ISVs purely because they don’t have the Adaptation Kit and this is for example one of the added values given by Technical Support.

5) Would you mind briefly explaining the difference between Windows Mobile and Windows CE?

Windows Mobile is based on Windows CE: it’s a special configuration of Windows CE modules put together by OEMs, which must pass a certification process in order to have the “Windows Mobile-Logo”. For example, every Windows Mobile device must have the Connection Manager: this is simply one of the requirements that must be fulfilled. But the bits in many cases are the same, and that’s why it’s so useful for ISVs to download the Evaluation Edition of Windows CE 5.0 to have plenty of native sample source code available. Despite the names, Windows Mobile 6 is NOT based on Windows Embedded CE 6.0 – probably the next version will be, so ISVs will finally have plenty of Virtual Memory to leak! :-) [Christopher - see the following post for further details]

6) I notice your blog posts are currently fairly evenly split among managed (.NET CF) and unmanaged (C / C++) posts. In your job supporting third party developers what do you see developers utilising out in the field?

Many have switched to managed development, but on Windows CE and Windows Mobile there are many topics that are better covered by native development. And that’s why OpenNETCF’s Smart Device Framework has been so successful.

7) When you are personally coding what language / environment do you prefer?

I prefer C#, now on Visual Studio 2008. My background was C/C++, not VB — therefore I found it easier to migrate to. Obviously there are many VB developers out there and I can handle requests about .NET CF applications written in VB.NET.

8) Do you carry a Windows Mobile PDA or Smartphone with you? If so what model?

Sure! And more than one! :-) Many times we have to deal with test devices with test platforms running on them. For example, lately I was carrying a very old HTC Tornado running the now just-released Windows Mobile 6.1! You see, “just-released” means “just-released to OEMs”: now they’re packaging ROM Upgrades for some existing Windows Mobile 6 devices and also will ship brand new devices, internally it’s been tested for a while.

9) What Windows Mobile feature couldn’t you live without (or conversely what feature do you find the most lacking or missing)?

I really enjoy using Windows Live for Mobile. Regarding missing or lacking feature I can’t express myself knowing the ones that will be introduced in the future! :-)

10) Due to supporting other developers are there any resources (or tools) that you would recommend for developers new to the Windows Mobile environment?

There are many tools available to programmers, but probably the one I use the most is the Device Emulator. Obviously if you have to deal with specific “real” features, say barcode-scanning, the emulator can’t help. But all the new features introduced in v3.0 and in the Windows Mobile 6 SDKs help a lot, and remember that if an issue is reproducible on the emulator then it’s sure that that it’s not related to a customisation of the OS done by the OEM: hence, it’s easier to troubleshoot. Then, surely every serious development should include Hopper in their tests. For managed development, you can’t live without the NETCF v3.5 Power Toys, while for native development remember you have the Application Verifier for Windows Mobile. And sometimes I find myself still using the (quite old) Windows Mobile Developer Power Toys!

Then I think having a repository of sample source code is always good. Re-using code is obviously something that a developer should do… why re-invent the wheel each time? And that’s why I usually prefer posts with some code in them… :-) So, here are some sources of sample source code:

Native:

Managed:

Finally since you asked about “developers new to the Windows Mobile environment“ I can’t omit the Webcasts and the “How do I”-videos!

11) Do you have any closing comments?

A comment about Microsoft Technical Support. It’s simply great that nowadays many developers rely on newsgroups and forums! I was there when Microsoft newsgroups were born and personally helped them to grow up, until they became auto-sufficient thanks to the great support given by Microsoft MVPs. When you don’t find an answer through your favourite Microsoft newsgroup or MSDN forums (or whatever!), just give the Microsoft Technical Support the chance to show what added value it can offer. If you have a contract (“Premier” or “Partner”) you will already be using it. If you have a MSDN Subscription or simply bought a Visual Studio box, chances are that you don’t know that you have the opportunity to open Service Requests thanks to a certain number of so-called “incidents”… so my suggestion is: make sure you use everything you’ve paid for! :-)

### How to detect Windows Mobile 6.1 (Detecting AKUs)

Monday, April 7th, 2008

Windows Mobile 6 and 6.1 both share the same version of the Windows CE kernel (5.2) meaning that previous techniques to determine the version of Windows Mobile on a device need to be modified to differentiate between these two most recent versions. It is not enough to compare the major and minor version numbers of the kernel. One possible technique is to programatically determine the current AKU in use by the Windows Mobile device as outlined by this blog posting.

### What is an AKU?

An Adoption Kit Update (AKU) is an update to the Windows Mobile operating system which is akin to a service pack for a desktop version of Microsoft Windows. An AKU is usually a vehicle to ship an extra feature or fix required by a specific Windows Mobile device under development.

Typically the features enabled by an AKU require specific hardware (such as a new type of keyboard) meaning it does not make sense to make AKUs available to older devices. Occasionally an AKU enables significant features which are of a software nature. For example AKU 2.0 for Windows Mobile 5.0 introduced the Messaging and Security Feature Pack (MSFP) which enabled closer integration with Exchange Server 2003.

### Determining the AKU

Since an AKU typically needs specific hardware and generally doesn’t alter the end user behaviour of a device it isn’t typical to need to detect a device’s AKU. However when you must detect the AKU of a device you can look within the HKLM\SYSTEM\Versions registry key for a string value called not surprisingly Aku.

An example of how you may access this registry value is shown below:

using Microsoft.Win32;   private string GetAKUVersion() { RegistryKey key = null; string aku;   try { key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\Versions"); aku = (string)key.GetValue("Aku"); // Most of the time the AKU string is prefixed with a . // so remove it. if (aku.StartsWith(".")) aku = aku.Substring(1); } finally { if (key != null) key.Close(); }   return aku; }

The Channel9 Windows Mobile Developer Wiki contains a list of AKUs that enables you to match up AKUs with OS build numbers which is another way to determine which AKU is present.

### Sample Application

A small example application is available for download that demonstrates making use of the GetAKUVersion function outlined above to display the Windows CE Kernel and Adoption Kit Update version numbers for the device the application is currently running on.

If you run this application on a Windows Mobile 6.1 device you will notice that the AKU version is reported as 1.0 (or higher) compared to older Windows Mobile 6 devices which have an AKU version below 1.0 (such as 0.4.2). Both versions of Windows Mobile report the use of various builds of the Windows CE 5.2 kernel.

### Introducing the Christchurch Embedded .NET User Group (EDNUG)

Sunday, April 6th, 2008

Update: We have had to change the date of this presentation – it is now booked for the 22nd of April instead of the 16th.

I have recently became involved in starting up a new user group within the Christchurch area. Andrew Leckie, Andy Scrase, Bryn Lewis and myself are organising a user group to cover embedded development topics within the Microsoft environment.

If you work with or have an interest in embedded device solutions using technologies such as the .NET Micro Framework, Windows Embedded CE, Windows Mobile, the .NET Compact Framework, Embedded XP, or Microsoft Robotics Studio etc, then this is the user group for you!

At the moment we are organising our first user group event for the 16th of April. This first session will give an overview of the above technologies and give a synopsis of the future sessions and intended agenda for the user group. It will also be a chance for you to provide some early feedback on what else you may wish to have presented from local experts as future topics.

Further details will be able to be found via the newly created Christchurch Embedded .NET User Group website available at http://www.embedded.net.nz (one of my current tasks is to help flesh out this website). If you have any questions about this user group please don’t hesitate to contact me.

### Visual Studio Tip: Selecting a Deployment Device

Saturday, April 5th, 2008

Here is a small tip for C++ Smart Device developers who use Visual Studio. While developing native applications it is common to target an older version of the Device SDK in order to produce a single executable that will run on a wide range of devices. For example you may purposely target the Pocket PC 2003 Device SDK in order for your executable to be compatible with any Windows Mobile 2003, 5.0, 6 or 6.1 device.

One problem with this technique is that by default the target device drop down used to select the device used for deployment and debugging purposes is filtered to only show the devices that match the selected version of the Device SDK.

If your application makes use of functions such as LoadLibrary and GetProcAddress to conditionally take advantage of functionality present in newer versions of the Windows Mobile operating system (as discussed previously) it can be handy to debug your application on a more recent version of Windows Mobile while still compiling against the older version of the Device SDK.

Luckily this can easily be achieved, but the feature is slightly hidden. If you open the Project Properties dialog (right click on the project within Solution Explorer and select Properties) you will be able to find a “Deployment Device” setting within the “Deployment” section. You will notice that this combo box displays all currently installed emulators for all versions of Windows Mobile. By selecting an emulator from this list and clicking OK you will notice that the Target Device combo box updates to reflect your selection even if the selected emulator is for a different version of Windows Mobile.

### Creating custom animated wait cursors

Friday, April 4th, 2008

Most .NET Compact Framework developers will be familiar with the Cursor.Current property and how to display the standard Wait Cursor, but did you know that you could easily display your own custom cursor? This blog entry discusses how you can replace the standard wait cursor with your own application specific cursor. This is an ideal way to brand kiosk style applications for example.

### Creating a custom cursor

Recent versions of the Windows CE operating system (and hence Windows Mobile) support an OS API called LoadAnimatedCursor. This API enables you to specify a sequence of individual bitmap frames and will convert them into an animated cursor. For example an animated cursor of a rotating monkey could be made up of the following 4 bitmaps.

 101 102 103 104

The more frames the cursor consists of the smoother the animation will be. Individual frames within the animation should be 48×48 pixel bitmap resources within a *.dll or *.exe file. The bitmap resources are identified by a numeric ID and must be in sequential order (such as the values 101, 102, 103 and 104 used in the example above).

The id of the first bitmap, the total number of frames and the period of time to delay between frames is then passed into the LoadAnimatedCursor API which will return a handle to the newly created cursor (an HCURSOR). Passing this handle to the SetCursor API will then make the cursor visible on the screen.

Unfortunately the LoadAnimatedCursor function is not as easy to use from managed code as it should be. The API expects the bitmap images to be native bitmap resources meaning you can not store them within a *.resx resource file within your .NET Compact Framework application. The easiest way to store the bitmaps in the correct format is to create a native C++ DLL project. You can then remove all the C++ source files, leaving a sole Win32 *.rc resource file to which you can add the bitmaps to (as will be demonstrated later).

### Sample Application

The sample application available for download consists of two projects. The first (called AnimatedCursors) demonstrates how to create a resource only DLL that contains the bitmap images required for the two custom cursors shown above.

The second project is a C# example demonstrating how to use Platform Invoke to access theLoadAnimatedCursor and SetCursor APIs to display the custom cursors. This second project loads the custom cursors from the AnimatedCursors.dll file built by the first project.

The C# sample wraps up the required Platform Invoke code within a class called AnimatedWaitCursor. This class implements the IDisposable interface so that the following syntax can be used to display a custom cursor. This code structure should be familiar to anyone who has used MFC’s CWaitCursor class.

// Use the animated cursor that has 4 frames starting with // bitmap id 101, delaying 125 milliseconds between each frame. string dll = @"\path\to\some.dll"; using (AnimatedWaitCursor cursor = new AnimatedWaitCursor(dll, 101, 4, 125)) { // do some long running task }

### Using VB.NET with the .NET Micro Framework

Tuesday, April 1st, 2008

This blog entry explores if it is possible to run VB.NET code on a .NET Micro Framework device. The current Visual Studio integration for the .NET Micro Framework only supports C# development, but since the framework is based upon the CLR runtime it theoretically supports development in any language that can be compiled down to Microsoft Intermediate Language (MSIL) code. So can we compile a VB.NET application for a .NET Micro Framework device and if so what kind of limitations or issues are we likely to come across? Read on to find out the results of some early experiments…

### A sample application

The first thing we need is some VB.NET code to attempt to compile. For this I have written the following WPF application.

Imports System Imports Microsoft.Spot Imports Microsoft.SPOT.Presentation Imports Microsoft.SPOT.Presentation.Media Imports Microsoft.SPOT.Presentation.Shapes   NameSpace HelloWorldVB Public Class Program Public Shared Sub Main() Dim app as Application = New Application()   ' Create a window object and set the size to ' the size of the display Dim mainWindow as Window= New Window() mainWindow.Height = SystemMetrics.ScreenHeight mainWindow.Width = SystemMetrics.ScreenWidth   ' Add a green rectangle as the sole child ' control of the window Dim rect As Rectangle = new Rectangle() rect.Fill = new SolidColorBrush(CType(&HFF00, Color)) mainWindow.Child = rect   ' Make the window visible mainWindow.Visibility = Visibility.Visible app.Run(mainWindow) End Sub End Class End Namespace

This application simply displays a full screen window that is coloured Green. This is a reasonably simple application that doesn’t make use of too many VB.NET language or .NET Micro Framework features so is an ideal starting point.

### Compiling the application

The first step is to use the standard VB.NET command line compiler (vbc.exe) to compile the source code into a standard executable. We can do this by using the following commands at a command prompt:

SET NET_BIN=C:\Windows\Microsoft.NET\Framework\v2.0.50727 SET MF_BIN=C:\Program Files\Microsoft .NET Micro Framework\v2.0.3036\Tools SET MF_LIB=C:\Program Files\Microsoft .NET Micro Framework\v2.0.3036\Assemblies   "%NET_BIN%\vbc.exe" /netcf /define:_MYTYPE=\"EMPTY\" /reference:"%MF_LIB%\Microsoft.SPOT.Graphics.dll" /reference:"%MF_LIB%\Microsoft.SPOT.TinyCore.dll" /out:HelloWorldVB.exe /target:exe Program.vb

This is all fairly standard stuff for command line VB.NET compilation, however there are two things to note. First we have used the /netcf argument which causes the compiler to target the .NET Compact Framework. This removes language functionality (such as late binding) that depend upon aspects of the full .NET framework.

The second thing to note is the define which sets _MYTYPE to EMPTY. As discussed by the “Customizing Which Objects are Available in My” article on MSDN setting this define to EMPTY will cause the VB.NET compiler to not generate a My namespace. The My namespace is typically used by VB.NET developers to get quick access to convenience functions for things such as File IO and networking functionality, but the code emitted by the VB.NET compiler is not suitable for the .NET Micro Framework base class libraries.

### Transforming the executable

Now that we have compiled the VB.NET code into MSIL we need to run the executable through an application called the Meta Data Processor. This pre-processes the MSIL based executable into a more efficient and smaller format that is suitable for use by the interpreter that forms the core part of the .NET Micro Framework runtime.

The following command line will convert the HelloWorldVB.exe executable into a HelloWorldVB.pe file that is suitable for execution by the .NET Micro Framework.

"%MF_BIN%\MetaDataProcessor.exe" -loadHints mscorlib "%MF_LIB%\mscorlib.dll" -parse HelloWorldVB.exe -minimize -compile HelloWorldVB.pe

You should notice that HelloWorldVB.pe is significantly smaller than HelloWorldVB.exe and even while viewing it using Notepad it clearly shows that there is less unnecessary “baggage”. For instance there is no string stating “This program cannot be run in DOS mode”.

### Running the application

Now that we finally have what appears to be a compiled VB.NET application in a form that is usable by the .NET Micro Framework we need to figure out a way to load it into our .NET Micro Framework emulator or device.

The following command line launches HelloWorldVB.pe within the sample emulator that comes with the .NET Micro Framework SDK.

"%MF_BIN%/Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe" /load:HelloWorldVB.pe /load:"%MF_LIB%\mscorlib.pe" /load:"%MF_LIB%\Microsoft.SPOT.Native.pe" /load:"%MF_LIB%\Microsoft.SPOT.TinyCore.pe" /load:"%MF_LIB%\Microsoft.SPOT.Graphics.pe"

At this point in time I have not investigated how to deploy *.pe files to actual devices.

### Conclusion

This experiment demonstrates that at a technical level it should be possible for the .NET Micro Framework to eventually support the execution of applications written in VB.NET. It does however demonstrate that at present there are a couple of hurdles to overcome, mainly in the code generated by the VB.NET compiler having dependencies on framework functionality not present by the .NET Micro Framework. Not being a VB.NET expert I wonder how far you can go before finding other problems? My next step is to figure out how to deploy *.pe files to an actual device so that I can verify that HelloWorldVB.pe actually does run on a physical device.

I am also interested in investigating the MetaDataProcessor.exe application in further depth. Is anyone aware of additional documentation for this tool? By running it from the command line it is apparent that it has a wide range of command line arguments, but I have presently been unable to find information about it usage.