Monthly Archives: August 2007

Write Code Once For Both Mobile And Desktop Apps



In a previous article I wrote about the technique used by Mobile Client Software Factory to do Microsoft Test automated testing in device projects.

MSDN magazine have now published a magazine article that explores the technique for developing other kinds of assemblies.  They also make the point that Compact Framework assemblies are “retargetable” (able to run on either platform ) whereas full framework assemblies are not.

This is not always ideal, as sometimes you may want to take advantage of desktop platform features.

The recommended technique involves sharing source, yet having two project files, targeting each different platform in the same project directory. 


 Share Code: Write Code Once For Both Mobile And Desktop Apps — MSDN Magazine, July 2007

Unit Testing Smart Device Projects

Victory for all Media Center Users in Australia



I believe a problem with Media Center adoption in Australia has been access to a good free Electronic Program Guide.   In other countries it’s tkan for granted, but for MCE (and other Media Center) users, getting an EPG becomes a real drama.    Undoubtedly the EPG functionality is an essential piece of the Medic Center value proposition.

Apparently this is due to the local television stations preventing providers from creator.

The best option (only reliable option?)  I’ve found is is IceTv (which I use), which is a “paid for” service.  Apparently even they have been experiencing ongoing legal battles to keep their service running.  (I used to be under the impression they were the only “sanctioned” provider”)

The great news is that IceTv has just won a landmark legal battle to publish the guide, which means others will undoubtedly follow.

Read all about it here:

Nine loses electronic program guide case – Home Theatre – AtHome – Technology

Simple Inter-Process Communication In VB.Net



There are plenty of articles around for inter process communication, using remoting, custom windows messages and named pipes.  In my .net career I think I’ve used all of them.  In this article I’ll outline a technique I’ll be using that I think is quite simple.

In .net Framework 2.0, Microsoft introduced the new System.Runtime.Remoting.Channels.Ipc   remoting channel , which provides one of the easiest (prior to using WCF) techniques.

In this example we have a single server process which is communicated to via client processes.



Firstly, as with all remoting it is necessary to share a type that defines the api you desire between client and server processes.  One of the easiest things to do is to create an interface.

For the sake of this example, I created an assembly called “Shared Interfaces” containing an interface called “ICommunicationService”:

Public Interface ICommunicationService
Sub SaySomething(ByVal text As String)
End Interface



For the Server in this example, I created a console application (it can be any sort of process).

The Server project contains two classes:

  • An implementation of ICommunicationService called “CommunicationService”
  • A Main that registers to CommunicationService class for acess

The CommunicationService class implements the interface and inherits from MarshalByRefObject :

Public Class CommunicationService
Inherits MarshalByRefObject
Implements SharedInterfaces.ICommunicationService

Public Sub SaySomething(ByVal text As String) Implements SharedInterfaces.ICommunicationService.SaySomething
Console.WriteLine(“The client said : ” & text)
End Sub
End Class

The main registers the type:

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Module Main
Sub Main()
Dim ipcCh As IpcChannel
ipcCh = New IpcChannel(“IPChannelName”)

ChannelServices.RegisterChannel(ipcCh, False)
RemotingConfiguration.RegisterWellKnownServiceType( _
GetType(CommunicationService), “SreeniRemoteObj”, _

Console.WriteLine(“Press ENTER to quit”)
End Sub
End Module



The client project is written as a Winform with a textbox and a button.  The button click contains this code:

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim ipcCh As New IpcChannel(“myClient”)
ChannelServices.RegisterChannel(ipcCh, False)

Dim obj As SharedInterfaces.ICommunicationService = _
DirectCast(Activator.GetObject(GetType(SharedInterfaces.ICommunicationService), _
“ipc://IPChannelName/SreeniRemoteObj”), SharedInterfaces.ICommunicationService)

End Sub

End Class

The code basically gets a reference to the remote object and invokes the “SaySomething” message, passing through a value.

As you can see, it doesn’t take much code to communicate between processes.


Further improvements to the code will involve ensuring security (making sure that only desirable client processes are calling).

Download a zip file containing the entire project for Visual Studio 2008.


A reference "to that project" could not be added


As part of my research into doing test driven development on the Windows Mobile platform, I tried to create a “smart device” project level reference.

(See the post Unit Testing Smart Device Projects for more information about using Microsoft Test and unit testing on Windows Mobile)

As I haven’t found the information anywhere else, I thought I’d post my problem and the solution:

The Problem

When my test project was in Visual Basic, I got this brutal error message:

A reference to xxxxxxxxx could not be added:


A CSharp test project did manage to get to add the reference, but only after getting this message:


Does this mean I’ve finally found something CSharp can do better than VB.Net?  Surely not!

The Solution

After a great deal of messing around, I tried using the Microsoft Test Test Wizard to create the Visual Basic test project.  This worked.  The reason this worked was that it took a file reference instead.

So there’s your workaround.  Use a file reference.

Unit Testing Smart Device Projects


Screenshot of the Smart Client Software Factory's Gui Test Runner

A way of doing Test Driven Development on the Windows Mobile platform in the early days was not particularly easy.

For the development of Webby I created my own NUnit clone that worked inside the exe in debug mode.  This worked really well, but it was limited and I would have preferred something that was integrated into the IDE.

The developers of the “Mobile Client Software Factory” at Microsoft Patterns and Practices felt the need to create a unit testing environment that would enable full “test first” development.  Recently I had the need to investigate their solution, and have found very good.

The factory provides comprehensive unit tests for the application blocks that come with the factory, but more interestingly it provides a way for you to use the same testing framework.

This article below gives an outline of how tests are structured and how to do it.  

The structure of the tests

The test classes utilise the “Visual Studio Team Suite” attribute test markup ([TestClass], [TestMethod] etc).

These test classes are used by two test projects (assemblies):

  • A desktop test project for Visual Studio 2005 Team Suite
  • A mobile class library for running the unit tests on a mobile device

Both the desktop and mobile projects reside in the same project folder (with different names)

Creating the tests

The following procedures describe how you should create and run unit tests
To create and run unit tests on the desktop

  1. Create a Visual Studio 2005 Team System Edition test project that will run unit tests on the desktop.
  2. Add the <TestClass>, <TestMethod>, <TestInitialize>, and <TestCleanup> attributes described earlier to your classes to indicate which are test classes, test methods, initialization methods, and cleanup methods.  (TIP: Reference the application exe or dll as a “File Reference”)
  3. Run these unit tests using Visual Studio 2005 Team System or the TestDriven.NET test runner until all the tests pass.

Next, you can adapt these tests to run on the mobile device. The following procedure describes how you can use the GuiTestRunner utility to run your unit tests in the device emulator or on a mobile device.

To run unit tests in the emulator or on a device

  1. Add the following projects to your application project:
    • GuiTestRunner.csproj from the Tools\CFUnitTester\GuiTestRunner folder
    • TestRunner.csproj from the Tools\CFUnitTester\TestRunner folder
    • UnitTesting.csproj from the Tools\CFUnitTester\UnitTesting folder
  2. If you want to use the test utilities in your tests, also add the TestUtilities.csproj project from the Tools\TestUtilities folder. This project includes utilities to help you read application resources, access the application runtime folder, and provides stopwatches for measuring performance.
  3. Click Add on the File menu, and then click New Project. In the left-side tree view of the Add New Project dialog box, click Windows Mobile 5.0 Pocket PC. In the right-side window of this dialog box, click Class Library. Click OK to add the new project to your existing solution. Use the naming convention for test projects “[Module to be tested].Tests.CF“.
  4. Close Visual Studio and, in Windows Explorer, move your new Class Library project into same folder as desktop test project. This allows the device test project to share the same files as the desktop test project more easily.
  5. Re-open Visual Studio, and open your application solution. In Solution Explorer, right-click the References entry for your application project, and then click AddReference. On the Projects tab of the AddReference dialog box, select your test project, and click OK.
  6. With the device test project selected in Solution Explorer, click Show AllFiles on the Project menu. This reveals all files and folders in the same folder as the desktop test project.
  7. Select all the test and supporting files in Solution Explorer, right-click, and then click Include in Project.
  8. Add the compiler directive to select the appropriate test class namespace at compile time.

    #if PocketPC
     Imports Microsoft.Practices.Mobile.TestTools.UnitTesting
     Imports Microsoft.VisualStudio.TestTools.UnitTesting

  9. In Solution Explorer, right-click your test project, and then click Properties. On the Properties page, click the Devices tab. Change the value for the Output file folder in the Deployment Options section to %CSIDL_PROGRAM_FILES%\GuiTestRunner to ensure that your tests deploy to the same folder as the as the GuiTestRunner utility.
  10. Deploy and execute the GuiTestRunner utility


So what’s so good about the iPhone? (WebBrowser)


Why is web browsing the iPhone so cool then?  Well I can’t answer that question with certainty, as I don’t have access to an iPhone. 

But I’ve seen a few videos on the subject and will list my thoughts.  Feel free to post any things people feel really “make it”.

Powerful features to me are:

  • Thumb scrolling
  • Thumb zoom (seems awkward, but seems  to  work)
  • Strong animation support throughout to give an “organic” feel.  The animations are contextual and enhance the usability of the program.
  • Orientation awareness

I think all these features are intrinsic to the iPhone user experience and are not peculiar to safari.

Other interesting features:

  • Cool thumbable “multiple page” interface. (Tab substitute)
  • “Full Screen” mode  just seems to happen intuitively
  • Search field “appears” when url field is focused
  • I like the bookmarks “slide up”. Much smoother than traditional PPC menus.

I believe the “usability” of applications like this is going to be “expected” in the future.  Software developers will really have to take this seriously in order to  survive.

I still think Webby will still have much to offer, even in an iPhone world.  Stay posted.


So easy even a 2 year old can do it


31July07 131

Creating user experiences that are intuitive and rewarding for just about anyone is one of the most interesting aspects of my work.

I frequently agonize about the design of programs, worrying whether normal people will be able to understand how to interact with them.  Perhaps I shouldn’t worry too much.  My 2 year old seems to have an uncanny ability to use electronic devices, which should be a credit to the designers.

A list of things my two year old can do (that I don’t want her to do), without any training:

  • In a 5 second burst, using the computer mouse and keyboard to wreck havoc on my Windows Desktop (this is not unique to my child.  A smiling little boy wandered over to me yesterday in the doctor’s waiting room and managed to do the same thing on my laptop in less than 2 seconds)…..Let me assure you that Visual Studio is NOT child-proof.
  • Eject the PCMCIA card from my laptop and bring it to me whilst I am cooking (it happens frequently, let me assure you)
  • Eject the SD wireless networking card from my PDA and leave it neatly next to the pda (she wouldn’t dare show me that one)
  • Switch off our media center (c0mputer) using it’s hardware button when the show is at it’s most interesting (while the audience on the couch yell warnings)
  • Switch on most computers the house whenever she feels like it
  • Access the Internet with mummy’s mobile phone (we suspect that the phone company may have called one day and tutored her on how to do this…there can be no other explanation)
  • Find the “stop” button on the media center remote
  • Pulls out my PDA stylus and manages to run virtually every program on the thing
  • Turn on the phone and lock it out so we have to call the phone company
  • Turns on our digital camera, watches previous videos and takes pictures
  • Turns the heater off and on (of course she’s not allowed to!)

Perhaps I need to model my designs on modern electronics, as these seem to require no prior learning.