MSMQ on Pocket PC 2003

Introduction

A few years ago mainstream software development was all about desktopsand servers, both being Personal Computers. This is rapidly changing as moreand more devices emerge. Today's world has Smartphones, Pocket PCs, TabletPCs, Media Centers and many more to emerge. As complex as it is tounderstand all these devices and their differences, Microsoft has made itequally complexit to understand the different Windows brands � Windows Embedded,Windows CE, Windows Mobile, etc. A few years ago it seemed to be cool andbleeding edge to support different devices other then the mainstream PC. Butas more devices emerge and as it becomes easier to develop software forthose devices, the more rapidly consumers and corporations will adopt them.Afew years from now it will be essential to support such devices and fordevelopers to have experience with development on such devices. This articlebuilds on top of the existing article "MSMQ, your reliable asynchronousmessage processing". It will show how MSMQ can be used on Pocket PC 2003 andat the same time provide an introduction to mobile development and theCompact Framework (CF).

 

Understanding the different Windows brands

Microsoft uses three main Windows brands. Each brand is targeted towards adifferent set of devices. There are gray areas between the different brands,but the device to support will determine which Windows version to use:

 

  • WindowsEmbedded � This encompasses all versions of Windows targeted towardsany device other then the PC (desktop and server). Windows Embeddedconsists of two main brands � Windows XP Embedded and Windows CE.
  • WindowsXP Embedded � This is a componentized version of Windows XPProfessional. Thus you select from the existing Windows XP Professionalcomponents which ones you want to include in your OS image. This allows youtocreate smaller OS images for different devices while still supporting anyWindows-based application (as long as the components the applicationrequires are included in the OS image). Windows XP Embedded only supportsIntel x86 hardware and is not a real time OS. Examples would be kiosks,retail devices, ATM's, etc.
  • Windows CE � Is a real time operating system which also supportsplatforms other than Intel x86. It is not bound to a specific device butrather contains components to support a wide variety of small devices.
  • WindowsMobile � Microsoft created Windows Mobile to provide a richexperience for end users as well as to provide strict guidelines for PocketPCsand Smartphones. Windows Mobile only runs on devices which support theWindows Mobile standard. The three main types of devices supported are:
    • PocketPC � Windows-based PDAs which support WiFi and Bluetooth andprovide mobile Word, mobile Excel, mobile Outlook and more.
    • Smartphones� Mobile phones which also support emailing, text messaging, web browsingand instant messaging.
    • PocketPC phone editions � For devices which combine PDA-type features withyour mobile phone. This supports all features of Pocket PC andSmartphone.

The diagram below visualizes the three brands. This is not a completediagram but rather concentrates on the Windows CE and Windows Mobile brands.It also shows the development tools available to build applications on theseplatforms. This MSDN article answers a number of questions about how to developfor these devices and platforms.

Windows Mobile CE Embedded MSMQ on Pocket PC 2003

Microsoft also ships a Compact Framework used to build .NET applications forWindows CE and Windows Mobile (both Windows Pocket PC and WindowsSmartphone).

 

Building your Pocket PC 2003 application

When you create a new project you can select the project type (list on theleft side). Under Visual Basic and under Visual C# you see an entry called"Smart Device". Underneath it you find Pocket PC 2003, Smartphone 2003 andWindows CE. These are the three different devices you can use the CompactFramework on and which VS.NET 2005 allows you to create applications for.Youcan create for each an application (Windows forms), class library or controllibrary (not supported for Smartphones). This by default references theCompact Framework. Under the references you suddenly also see an "mscorlib",which is the "mscorlib" for the Compact Framework. When you add newreferences you see also that the list is smaller. That is because theCompact Framework only supports a subset of the full framework. The CompactFramework 2.0 added the System.Messaging assembly/namespace which providesfull support for MSMQ on Pocket PC and Windows CE but not for Smartphones.

Windows forms is available for all three devices and differs from thetraditional desktop Windows forms in that the screen size available is muchsmaller. The designer shows a fixed-size window which reflects the sizeavailable on selected devices. How to add controls through the toolbox, howto position and resize it, how to set its properties and how to add eventhandlers is the same as for the traditional desktop Windows forms. The listof properties and events will be shorter as not all are supported by theCompact Framework, or more specifically by the devices themselves.

When running the application the VS.NET IDE shows a deployment dialog. Youcan choose where to deploy and run the application. VS.NET providesEmulators so you can run and test the applications without requiring anactual physical device. Emulators are available for Pocket PC 2003,Smartphone 2003 and Windows CE 5.0. You can also choose a form factor,meaning the skin used when showing the device in the emulator. For exampleyou can choose between a "Pocket PC 2003 Portrait" and a "Pocket PC Phone2003 Portrait".

 

Running on a Pocket PC 2003 Emulator

Choose "Pocket PC 2003 SE Emulator" to deploy and run your application onthe Pocket PC Emulator. This starts a virtual machine and loads the PocketPC 2003 OS into that virtual machine. Devices like Pocket PCs andSmartphones can utilize an Intel x86 processor or an ARM (Advanced RISC Machines) processor. The emulators which come with VS.NET are emulating ARM-baseddevices. All device emulator images are stored in the following location -"C:\Program Files\MicrosoftVisual Studio 8\SmartDevices\Emulators\Images".You find the Pocket PC image under the sub folder "PocketPC\2003\1033" andthe Smartphone image under the sub folder "Smartphone\2003\1033". Keep inmind that because emulators are emulating a Pocket PC or Smartphone it willalways be slower then an actual device itself.

The emulator window shows a Pocket PC booting up, like a r
eal Pocket PC. Itthen asks in the emulator window if the Pocket PC is connected to theInternet or Work – choose "The Internet". Since this is the first time theemulator is started and no Compact Framework is yet loaded, VS.NET firstdeploys the Compact Framework onto the emulator. After that VS.NET showsagain the dialog to choose where to deploy the application (it is unclear tome why this is required, but if you always deploy to the same device oremulator you can unselect the option "Show me this dialog each time I deploythe application"). Now VS.NET starts deploying your application files ontothe Pocket PC emulator. When completed VS.NET will start the application onthe Pocket PC while remotely connecting to it so you can debug theapplication remotely. In our example it will show an exception as soon as aSystem.Messaging type gets loaded and called. This is the case because MSMQis not yet installed and configured on your Pocket PC emulator.

 

Loading and installing MSMQ on the Pocket PC emulator

You can tell the VS.NET IDE to upload not just the project files but alsoany other files you need to get onto the Emulator. The MSMQ redistributablefiles can be found at the following location – "C:\Program Files\MicrosoftVisual Studio 8\SmartDevices\SDK\SDKRedist\MSMQ".Because the emulator is ARM-based we take them from the ARM sub folder. Addall six files to the project and set "Build Action" in the file properties(in VS.NET) to "Content". All files marked as content will be deployed inthe same folder as your project. To change the location where yourapplication gets deployed to, bring up the Project properties (in VS 2005double click on the item Properties). Go to the "Device" tab and change the"Output file folder". This by default always points to "\Program Files"followed by your project name. Also any files you marked with "Content" inthe build action are deployed into this folder. To deploy your applicationagain, run it again, or choose "Build | Deploy Solution". After redeployingthe application, go to the Pocket PC emulator window so we can setup MSMQ onit.

 

The basics of using the Pocket PC Emulator

The Emulator shows you Pocket PC as it would be on any real Pocket PCdevice. In the upper left corner you see the "Windows start button". Clickon the start button and it will show the start menu. Select "Programs" tobring up the installed programs, one of them being the "File Explorer". Openthe "File Explorer" by double clicking on it which shows by default the "MyDocuments" folder. Click on the white space at the bottom of the fileexplorer and keep the mouse pressed till the popup menu shows. Select fromthe menu "View All Files" so we see all files. Right under the Windows startbutton in the upper left corner it shows "My Documents" with a down arrow.This is your current location and clicking on the down arrow brings up amenu. Click on it and select "My Device" to jump to the root folder of yourdevice. Next double click on "Program Files". This shows the "Program Files"folder where you see a "NET CF 2.0" folder where VS.NET deployed the CompactFramework as well as an "MSMQ Pocket PC" folder where our application hasbeen deployed. Now we want to copy the MSMQ redistributable files to theWindows folder. Go to the "MSMQ Pocket PC folder" and select the followingsix files (by holding down the CTRL key and clicking on each file) � visadm,msmqrt, msmqd, msmqadmext, mqoa and msmqadm. Click on one of the selectedfiles and hold down the mouse till the popup menu shows, then select "Copy".Next click again on the arrow beside the current folder location (rightunder the Windows start button) and select "My Device" from the menu. Thisshows again the root folder of the device. Double click on the "Windows"folder, press the END key to jump to the end of the file list, click on anempty space and hold the mouse key down till the menu appears and select"Paste". Now all six files have been copied to the Windows folder.

Next we configure MSMQ on this Pocket PC. This requires changing the defaultPocket PC name. Click on the Windows start button and select "Settings" fromthe start menu. Select the "System" tab at the bottom and then double clickon the "About" icon in the list. This shows the Windows "about" screen.Selectthe tab "Device ID" at the bottom which shows the current Device name as"Pocket_PC". Change the name to something like "EnterpriseMinds" and clickthe Ok button in the upper right corner. This brings you back to theSettings screen which you can close with the "X" in the upper right corner.This brings you back to the File Explorer which still shows the files wecopied into the Windows folder. Double click on "visadm" to bring up thevisual MSMQ administrator console. Click on the "Shortcuts" button andselect "Install" from the menu. Click again on the "Shortcuts" button andselect "Register" this time. Next we need to restart the Pocket PC for thechanges to take effect. Click on the "Exit" button to close "visadm" andnext on the Emulator window itself click on the "Power button" (upper rightcorner). This will ask you if you are sure and you say yes which shuts downthe device, shows a black screen and then boots it up again (this may take awhile). Now we have reset the device and we want to check if MSMQ has beenset up properly. Go back to the File Explorer, which now also appears in thestart menu and by default jumps back into the Windows folder. Start "visadm"again, click on the "Shortcut" button and select "Verify". This shows thatMSMQ has been properly installed. Now we can go back and run our sampleapplication. First close "visadm" with the "X" in the upper right corner, aswell as the File Explorer. Run again the sample application from your VS.NETIDE, which will redeploy any changed files, then launch our sampleapplication while still being connected to it remotely so you can debugthrough the VS.NET IDE.

 

Changes to the MSMQ Pocket PC sample application

This sample application is based on the original desktop applicationattached to the article "MSMQ, your reliable asynchronous messageprocessing". There are five main differences in the MessageQueueManagertype:

 

  • GetMessageQueueProperties() � The MessageQueue type does notsupport the following four properties � Authenticate, Category,EncryptionRequired and MulticastAddress. These four properties have beenremoved.
  • GetMessageDetails() � The Message type does not support thefollowing ten properties � AttachSenderId, Authenticated,AuthenticationProviderName, AuthenticationProviderType, ConnectorType,EncryptionAlgorithm, LookupId, TransactionStatusQueue, UseAuthentication andUseEncryption. These ten properties have been removed.
  • StartTransaction() � The type MessageQueueTransaction is notsupported at all. Only single message transactions are supported. So wecompletely removed this method. 
  • SendMessage() � Insteadof using a MessageQueueTransaction type we use theMessageQueueTransactionType enumeration to specify if this message is sentunder a single-message-transaction or non-transactional.
  • GetListOfPrivateMessageQueues() � Used Environment.MachineNamewhich is not supported by the Compact Framework. This is set by default to"." which means local machine.
>All other System.Messaging types are fully supported. MSMQ on Pocket PC 2003only allows you to work with local private message queues (no remote privatequeues and no public queues).

 

Some more useful comments on the Emulator and CF

This MSDN article answers a wealth of questions when it comes todeveloping with the Compact Framework. When exiting the emulator it asks youif you want to save the state. This allows you to save its current state,for example our MSMQ configuration, changes to the device ID, etc. This alsomeans that VS.NET doesn't have to deploy the Compact Framework next time asit is already on the device. Next time the emulator is started up itremembers that exact state. You can reset the emulator, which will removeallsaved state and bring the emulator back to its original configuration. Inthe emulator window click on the menu "File | Reset".

Your emulated Pocket PC has an IP address assigned to it. Open up thesettings (select Settings from the Windows start menu), select the"Connections" tab and then double click on the "Network Cards" icon. Out ofthe box the network card "NE2000 Compatible Ethernet Driver" is mapped tothe physical network card on your machine. Through that the Pocket PC getsnetwork access. The drop down list "My network card connects to" has thevalue "The Internet" selected out of the box. Leave this value and click onthe NE2000 driver. This brings up a window which shows you the current IPaddress. Ping that IP address from your physical machine and you will seethat you get a response back. Click ok in the upper right corner, click okto the message shown and then ok to close the connections window.

If you have no network connectivity or use an ISP which only allows a fewnamed machines to connect to the ISP but you already used all of those, thenuse the "Microsoft Loopback Adapter". Choose the "Add hardware" wizard fromthe control panel. It will first try to detect any new hardware and then askyou if the hardware has already been connected. Answer yes and from thefollowing list select the item "Add a new hardware device". Next select theoption "Install the hardware that I manually select from a list" and thenselect from the following list the item "Network adapter". From the listselect the "Microsoft Loopback Adapter" and finish the installation of thisadapter. When the adapter has been installed, open up the properties of the"My Network Places". You will see a new "Local Area Connection". Open itsproperties, select the item "Internet Protocol (TCP/IP) and open itsproperties. Choose the option "Use the following IP address" and enter as IPaddress "192.168.0.1" and as subnet mask "255.255.255.0" Click ok twice tosave the new IP settings for this "Microsoft Loopback Adapter". Finally weneed to configure the Pocket PC Emulator to use this Loopback Adapter. Inthe VS.NET IDE go to the menu "Tools | Options" and then in the list on theleft side choose the option "Device Tools" and then underneath it "Devices".This shows the list of devices on the right side. Select the item "Pocket PC2003 SE Emulator" and click on the Properties button. On the new dialogclick on the "Emulator Properties" button and on the next dialog choose the"Network" tab. The option "Enable NE2000 PCMCIA Network Adapter to bind to"is enabled and in the drop down below it has the item "Connected networkcard" selected. From the drop down list choose the "Microsoft LoopbackAdapter" and click ok three times to save the settings of each dialog. Nextlaunch the Pocket PC Emulator through the menu "Tools | Connect to Device",select the "Pocket PC 2003 SE Emulator from the list of devices tolaunch and click the "Connect" button. In the Pocket PC Emulator click onthe "Windows start button" and select Settings from the start menu. Selectthe tab "Connections" at the bottom and double click on the "Network Cards"icon. The drop down list "My network card connects to" has the option "TheInternet" selected. Keep that selection and click on the "NE2000 CompatibleEthernet Driver". In the new window select the option "Use specific IPaddress" and enter as IP address "192.168.0.2" and as subnet mask"255.255.255.0". Click on ok in the upper right corner, click ok on themessage box and again ok to close the "Connections" window. Finally we wantto test if we have connectivity (which assumes you have an IIS running onyour local physical machine). Click on the "Windows start button" and select"Internet Explorer" from the start menu. In the address bar type in the URLfor your local IIS which is "http://192.168.0.1". This brings up the homepage of your local IIS.

You can also share a folder on your local machine and connect to it throughthe Pocket PC Emulator which makes it easy to copy files onto the Pocket PC.First share a folder (right click on the folder and select "Sharing andsecurity", select the option "Share this folder" and enter a name, forexample MSMQ) and make sure that everyone has "read" rights to it. In thePocket PC Emulator open the File Explorer and then click on the "Open"button in the lower left corner. In the new window type in the network pathto connect to, for example "\192.168.0.1\msmq" which then opens that shareand you can copy files onto your Pocket PC. Please note that with VS 2005Beta1 I was unable to do this while using the "Microsoft Loopback Adapter".It showed the error "The network path was not found".

When you close applications on the Pocket PC with the "X" in the upper rightcorner, this does not really close the application. It just hides thewindow so it appears to be closed to the user. This is to improve overallresponsiveness of the Pocket PC. You can check which applications arerunning and can close them. Click on the "Windows start button" and select"Settings" from the start menu. Select the tab "System" at the bottom anddouble click on the icon "Memory". It shows the total memory available andhow much is used at the moment. Click on the tab "Running Programs" to see alist of running programs. Select the one desired and click "Stop" to closethe program or click "Stop All" to stop all programs.

 

Summary

Developing mobile applications, whether for Windows CE, Pocket PC orSmartphones can be a daunting task at the beginning, mostly due to the factthat there are many new things to learn � the Compact Framework, the PocketPC interface, how to work with the Pocket PC emulator, etc. The bigger issueis not that it is very complex to do but rather just getting a goodintroduction to it. Unfortunately the documentation available is ratherlacking. This article hopefully gives you a very good introduction aboutmobile development, about the Pocket PC interface and how to work with thePocket PC emulator. After getting over that initial learning curve you willsee that it is very easy to developer mobile applications with the CompactFramework and to test and debug them with the available emulators. If youhave comments on this article, please contact me @ klaus_salchner@hotmail.com. Iwant to hear if you learned something new. Contact me if you have questionsabout this topic or articl
e.

Download Source

 

About the author

Klaus Salchner has worked for 14 years in the industry, nine years in Europeand another five years in North America. As a Senior Enterprise Architectwith solid experience in enterprise software development, Klaus spendsconsiderable time on performance, scalability, availability,maintainability, globalization/localization and security. The projects hehas been involved in are used by more than a million users in 50 countrieson three continents.

Klaus calls Vancouver, British Columbia his home at the moment. His nextbiggoal is doing the New York marathon in 2005. Klaus is interested in guestspeaking opportunities or as an author for .NET magazines or Web sites. Hecan be contacted at klaus_salchner@hotmail.com or http://www.enterprise-minds.com .

Enterprise application architecture and design consulting services areavailable. If you want to hear more about it contact me! Involve me in yourprojects and I will make a difference for you. Contact me if you have anidea for an article or research project. Also contact me if you want to co-author an article orjoin future research projects!

Edited by Dwight Johnson

Most Commented Articles :

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!