MSMQ on Pocket PC 2003

Introduction

A few years ago, mainstream software development was all about desktops and servers, both being Personal Computers. This is rapidly changing as more and more devices emerge. Today's world has Smartphones, Pocket PCs, Tablet PCs, Media Centers, and many more to emerge. As complex as it is to understand all these devices and their differences, Microsoft has made it equally complex to understand the different Windows brands—Windows Embedded, Windows CE, Windows Mobile, and so forth. A few years ago, it seemed to be cool and bleeding edge to support different devices other then the mainstream PC. But, as more devices emerge and as it becomes easier to develop software for those devices, the more rapidly consumers and corporations will adopt them. A few years from now, it will be essential to support such devices and for developers to have experience with development on such devices. This article builds on top of the existing article "MSMQ, your reliable asynchronous message processing." It will show how MSMQ can be used on Pocket PC 2003 and at the same time provide an introduction to mobile development and the Compact Framework (CF).

Understanding the Different Windows Brands

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

  • Windows Embedded—This encompasses all versions of Windows targeted towards any device other then the PC (desktop and server). Windows Embedded consists of two main brands: Windows XP Embedded and Windows CE.
  • Windows XP Embedded—This is a componentized version of Windows XP Professional. Thus, you select from the existing Windows XP Professional components which ones you want to include in your OS image. This allows you to create smaller OS images for different devices while still supporting any Windows-based application (as long as the components the application requires are included in the OS image). Windows XP Embedded only supports Intel x86 hardware and is not a real-time OS. Examples would be kiosks, retail devices, ATMs, and so forth.
  • Windows CE—This is a real-time operating system that also supports platforms other than Intel x86. It is not bound to a specific device, but rather contains components to support a wide variety of small devices.
  • Windows Mobile—Microsoft created Windows Mobile to provide a rich experience for end users as well as to provide strict guidelines for Pocket PCs and Smartphones. Windows Mobile only runs on devices that support the Windows Mobile standard. The three main types of devices supported are:

    • Pocket PC—Windows-based PDAs that support WiFi and Bluetooth and provide mobile Word, mobile Excel, mobile Outlook, and more.
    • Smartphones—Mobile phones that also support e-mailing, text messaging, Web browsing, and instant messaging.
    • Pocket PC phone editions—For devices that combine PDA-type features with your mobile phone. This supports all features of Pocket PC and Smartphone.

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

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

Building Your Pocket PC 2003 Application

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

Windows forms are available for all three devices and differ from the traditional desktop Windows forms in that the screen size available is much smaller. The designer shows a fixed-size window that reflects the size available on selected devices. How to add controls through the toolbox, how to position and resize it, how to set its properties, and how to add event handlers is the same as for the traditional desktop Windows forms. The list of properties and events will be shorter because not all are supported by the Compact Framework, or more specifically by the devices themselves.

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

Running on a Pocket PC 2003 Emulator

Choose "Pocket PC 2003 SE Emulator" to deploy and run your application on the Pocket PC Emulator. This starts a virtual machine and loads the Pocket PC 2003 OS into that virtual machine. Devices such as Pocket PCs and Smartphones can utilize an Intel x86 processor or an ARM (Advanced RISC Machines) processor. The emulators that come with VS.NET are emulating ARM-based devices. All device emulator images are stored in the following location: "C:\Program Files\Microsoft Visual Studio 8\SmartDevices\Emulators\Images". You find the Pocket PC image under the sub folder "PocketPC\2003\1033" and the Smartphone image under the sub folder "Smartphone\2003\1033".

Note: Keep in mind that because emulators are emulating a Pocket PC or Smartphone, they will always be slower then an actual device itself.

The emulator window shows a Pocket PC booting up, like a real Pocket PC. It then asks in the emulator window whether the Pocket PC is connected to the Internet or Work; choose "The Internet." Because this is the first time the emulator is started and no Compact Framework is yet loaded, VS.NET first deploys the Compact Framework onto the emulator. After that, VS.NET again shows the dialog to choose where to deploy the application (it is unclear to me why this is required, but if you always deploy to the same device or emulator you can unselect the option "Show me this dialog each time I deploy the application"). Now, VS.NET starts deploying your application files onto the Pocket PC emulator. When completed, VS.NET will start the application on the Pocket PC while remotely connecting to it so you can debug the application remotely. In this example, it will show an exception as soon as a System.Messaging type gets loaded and called. This is the case because MSMQ is 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 also any other files you need to get onto the Emulator. The MSMQ redistributable files can be found at the following location: "C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SDKRedist\MSMQ". Because the emulator is ARM-based, you take them from the ARM sub folder. Add all 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 in the same folder as your project. To change the location where your application is deployed, bring up the Project properties (in VS 2005, double-click 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" in the build action are deployed into this folder. To deploy your application again, run it again, or choose "Build | Deploy Solution." After redeploying the application, go to the Pocket PC emulator window so you can set up MSMQ on it.

The Basics of Using the Pocket PC Emulator

The Emulator shows you Pocket PC as it would be on any real Pocket PC device. In the upper-left corner, you see the "Windows start button." Click the start button and it will show the start menu. Select "Programs" to bring up the installed programs, one of them being the "File Explorer." Open the "File Explorer" by double-clicking it; by default, it shows the "My Documents" folder. Click on the white space at the bottom of the file explorer and keep the mouse pressed till the popup menu shows. Select from the "View All Files" menu so we see all files. Right under the Windows start button in the upper left corner, it shows "My Documents" with a down arrow. This is your current location; clicking the down arrow brings up a menu. Click it and select "My Device" to jump to the root folder of your device.

Next, double-click "Program Files." This shows the "Program Files" folder where you see a "NET CF 2.0" folder where VS.NET deployed the Compact Framework as well as an "MSMQ Pocket PC" folder where your application has been deployed. Now, you want to copy the MSMQ redistributable files to the Windows folder. Go to the "MSMQ Pocket PC folder" and select the following six files (by holding down the CTRL key and clicking on each file): visadm, msmqrt, msmqd, msmqadmext, mqoa, and msmqadm. Click one of the selected files and hold down the mouse until the popup menu shows; then select "Copy." Next, again click the arrow beside the current folder location (right under the Windows start button) and select "My Device" from the menu. This again shows the root folder of the device. Double-click the "Windows" folder, press the END key to jump to the end of the file list, click an empty space, 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 default Pocket PC name. Click the Windows start button and select "Settings" from the start menu. Select the "System" tab at the bottom and then double-click the "About" icon in the list. This shows the Windows "about" screen. Select the tab "Device ID" at the bottom; it shows the current Device name as "Pocket_PC." Change the name to something like "EnterpriseMinds" and click the Ok button in the upper-right corner. This brings you back to the Settings screen that you can close with the "X" in the upper-right corner. This brings you back to the File Explorer that still shows the files you copied into the Windows folder. Double-click "visadm" to open the visual MSMQ administrator console. Click the "Shortcuts" button and select "Install" from the menu. Click the "Shortcuts" button again and select "Register" this time.

Next, we need to restart the Pocket PC for the changes to take effect. Click the "Exit" button to close "visadm" and next, on the Emulator window itself, click the "Power button" (upper-right corner). This will ask you if you are sure; say yes, which shuts down the device, shows a black screen, and then boots it up again (this may take a while). Now, we have reset the device and we want to check whether MSMQ has been set up properly. Go back to the File Explorer, which now also appears in the start menu and by default jumps back into the Windows folder. Start "visadm" again, click the "Shortcut" button, and select "Verify". This shows that MSMQ has been properly installed. Now, we can go back and run our sample application. First, close "visadm" with the "X" in the upper-right corner, as well as the File Explorer. Run the sample application from your VS.NET IDE again; this will re-deploy any changed files. Then, launch the sample application while still being connected to it remotely so you can debug through the VS.NET IDE.

MSMQ on Pocket PC 2003

Changes to the MSMQ Pocket PC Sample Application

This sample application is based on the original desktop application attached to the article "MSMQ, your reliable asynchronous message processing." There are five main differences in the MessageQueueManager type:

  • GetMessageQueueProperties()—The MessageQueue type does not support the following four properties: Authenticate, Category, EncryptionRequired, and MulticastAddress. These four properties have been removed.
  • GetMessageDetails()—The Message type does not support the following ten properties: AttachSenderId, Authenticated, AuthenticationProviderName, AuthenticationProviderType, ConnectorType, EncryptionAlgorithm, LookupId, TransactionStatusQueue, UseAuthentication, and UseEncryption. These ten properties have been removed.
  • StartTransaction()—The MessageQueueTransaction type is not supported at all. Only single message transactions are supported. So, we completely removed this method. 
  • SendMessage()—Instead of using a MessageQueueTransaction type, you use the MessageQueueTransactionType enumeration to specify whether this message is sent under a single-message-transaction or non-transactional.
  • GetListOfPrivateMessageQueues()—Used Environment.MachineName which 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 2003 only allows you to work with local private message queues (no remote private queues and no public queues).

Some more Useful Comments on the Emulator and CF

This MSDN article provides a wealth of answers when it comes to developing with the Compact Framework. When exiting the emulator, it asks you whether you want to save the state. This allows you to save its current state, for example our MSMQ configuration, changes to the device ID, and so forth. This also means that VS.NET doesn't have to deploy the Compact Framework the next time because it is already on the device. The next time the emulator is started up, it remembers that exact state. You can reset the emulator, which will remove all saved state information and bring the emulator back to its original configuration. In the emulator window, click the "File | Reset" menu.

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

If you have no network connectivity or use an ISP that only allows a few named machines to connect to the ISP but you already used all of those, use the "Microsoft Loopback Adapter." Choose the "Add hardware" wizard from the control panel. It will first try to detect any new hardware and then ask you whether the hardware has already been connected. Answer yes and from the following list select the "Add a new hardware device" item. Next, select the "Install the hardware that I manually select from a list" option and then select the item "Network adapter" from the following list. From the list, select the "Microsoft Loopback Adapter" and finish the installation of this adapter. When the adapter has been installed, open up the properties of the "My Network Places." You will see a new "Local Area Connection." Open its properties, select the item "Internet Protocol (TCP/IP)" and open its properties. Choose the option "Use the following IP address" and enter as IP address "192.168.0.1" and as subnet mask "255.255.255.0." Click Ok twice to save the new IP settings for this "Microsoft Loopback Adapter."

Finally, we need to configure the Pocket PC Emulator to use this Loopback Adapter. In the VS.NET IDE, go to the "Tools | Options" menu and then in the list on the left side, choose the "Device Tools" option and then, underneath it, "Devices." This shows the list of devices on the right side. Select the "Pocket PC 2003 SE Emulator" item and click the Properties button. On the new dialog, click the "Emulator Properties" button and on the next dialog, choose the "Network" tab. The "Enable NE2000 PCMCIA Network Adapter to bind to" option is enabled and the drop-down below it has the "Connected network card" item selected. From the drop-down list, choose the "Microsoft Loopback Adapter" and click Ok three times to save the settings of each dialog.

Next, launch the Pocket PC Emulator through the "Tools | Connect to Device" menu, select the "Pocket PC 2003 SE Emulator from the list of devices to launch, and click the "Connect" button. In the Pocket PC Emulator, click the "Windows start button" and select Settings from the start menu. Select the "Connections" tab at the bottom and double-click the "Network Cards" icon. The "My network card connects to" drop-down list has the "The Internet" option selected. Keep that selection and click the "NE2000 Compatible Ethernet Driver." In the new window, select the "Use specific IP address" option and enter as IP address "192.168.0.2" and as subnet mask "255.255.255.0." Click Ok in the upper right corner, click Ok on the message box, and Ok again to close the "Connections" window. Finally, we want to test whether we have connectivity (which assumes you have an IIS running on your local physical machine). Click the "Windows start button" and select "Internet Explorer" from the start menu in the address bar type in the URL for your local IIS, which is "http://192.168.0.1". This brings up the home page of your local IIS.

You also can share a folder on your local machine and connect to it through the Pocket PC Emulator; this makes it easy to copy files onto the Pocket PC. First, share a folder (right-click the folder and select "Sharing and security," select the "Share this folder" option and enter a name, for example MSMQ) and make sure that everyone has "read" rights to it. In the Pocket PC Emulator, open the File Explorer and then click the "Open" button in the lower left corner. In the new window, type in the network path to connect to, for example "\\192.168.0.1\msmq", which then opens that share and you can copy files onto your Pocket PC. Please note that with VS 2005 Beta 1, 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 right corner, this does not really close the application. It just hides the window so it appears to be closed to the user. This is to improve overall responsiveness of the Pocket PC. You can check which applications are running and can close them. Click the "Windows start button" and select "Settings" from the start menu. Select the "System" tab at the bottom and double-click the "Memory" icon. It shows the total memory available and how much is used at the moment. Click the "Running Programs" tab to see a list of running programs. Select the one desired and click "Stop" to close the program or click "Stop All" to stop all programs.

Summary

Developing mobile applications, whether for Windows CE, Pocket PC, or Smartphones can be a daunting task at the beginning, mostly due to the fact that there are many new things to learn—the Compact Framework, the Pocket PC interface, how to work with the Pocket PC emulator, and so forth. The bigger issue is not that it is very complex to do but rather just getting a good introduction to it. Unfortunately, the available documentation is rather lacking. This article hopefully gives you a very good introduction to mobile development, about the Pocket PC interface, and how to work with the Pocket PC emulator. After getting over that initial learning curve, you will see that it is very easy to develop mobile applications with the Compact Framework and to test and debug them with the available emulators. If you have comments on this article, please contact me at klaus_salchner@hotmail.com. I want to hear if you learned something new. Contact me if you have questions about this topic or article.

About the Author

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

Klaus calls Vancouver, British Columbia his home at the moment. His next big goal is running the New York marathon in 2005. Klaus is interested in guest speaking opportunities or as an author for .NET magazines or Web sites. He can be contacted at klaus_salchner@hotmail.com or http://www.enterprise-minds.com.

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

Edited by Dwight Johnson



Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Mobile is introducing sweeping changes throughout your workplace. As a senior stakeholder driving mobile initiatives in your organization, you may be lost in a sea of technologies and claims from vendors promising rapid delivery of applications to your employees, customers, and partners. To help explain some of the topics you will need to be aware of, and to separate the must-haves from the nice-to-haves, this reference guide can help you with applying a mobile strategy in the context of application …

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds