Welcome!

.NET Authors: Hovhannes Avoyan, Bruce Armstrong, Pat Romanski, Liz McMillan, Yeshim Deniz

Related Topics: .NET

.NET: Article

The Microsoft Device Emulator

A great productivity tool for Windows Mobile and Windows CE developers

Anyone who develops applications for devices can vouch for the importance of having a powerful emulator that can help accelerate the overall development and debugging process. This articles talks about the new Microsoft Device Emulator and how you can exploit some of its capabilities and make yourself a more productive Windows Mobile and Embedded developer.

Getting the Device Emulator
The Microsoft Device Emulator first shipped with Visual Studio 2005 in October 2005. The Microsoft Device Emulator emulates the ARM instruction set which implies that it provides a very high fidelity of emulation, especially on the Windows Mobiles devices which are based on the ARM Processor. This is a significantly different experience from the emulator that was shipped with earlier development tools, such as embedded Visual C++ and Visual Studio 2003, which shipped an emulator emulating the X86 instructions. In this article, you will see some of the benefits of using the ARM based emulator.

As mentioned above, installing Visual Studio 2005 will install Microsoft Device Emulator 1.0, however, if you wish to use only the Device Emulator, you can download it from the Microsoft Download Center. The download page is www.microsoft.com/downloads.

At the time this article was written, Microsoft Device Emulator Version 2.0 was available as a Community Technology preview download and would be shipping as part of the Windows Embedded CE 6.0 release within a couple of weeks. I highly encourage you to use the Version 2.0, as it not only enhances emulation performance significantly, but also adds many new emulation capabilities.

The download details for Version 2.0 can be found at www.microsoft.com/downloads/details.aspx?familyid= 13F5DE85-30CD-4506-9C5B-A2068FA1EE9E&displaylang=en.

It's a No-Touch Install
While the Microsoft Device Emulator setup package ships as an Installer package (MSI), the Device Emulator executable (DeviceEmulator.exe) itself can work without any kind of install requirements on the desktop. This means that you can enable a scenario in which you can host the device emulator and a device image on a remote machine, and then be able to run them from any other machine without having to install anything on it. This is a useful scenario in cases where, say, your sales force wants to demo an application installed on an emulator image but don't want to install anything locally on their machine. To achieve that, you can, for example, host a small batch file on an HTTP server which would load a pre-configured device image on the client machine without installing anything on the client machine.

For example, host a demo.bat file on your server:

http://mydemoserver/emulator/demo.bat

Then in the demo.bat, include something like this:

\\mydemoserver\emulator\deviceemulator.exe /s <filesname>.dess

When clicking on the link (The .BAT File) from a client machine, the emulator and the image would load on the client without any installation requirement.

Emulating ARM Instructions. So What's the Benefit?
As a Windows Mobile developer you have three advantages. The first one is that you no longer have to build two different binaries: one for an emulator and one for a device. The binaries compiled for your Windows Mobile device will work unmodified on the emulator as well, so there are fewer binaries to maintain. The second benefit is that there is now parity in the code that is executing on the device with what is running on the emulator, which means you can debug with a high degree of accuracy on the emulator itself.

The third benefit you get as a developer is indirect. It actually benefits the consumer of your application because now if they want to try your application without risking their device, they can run the application binaries on the emulator to experience your application. With high fidelity emulation of sounds and graphics, many apps will work just as well on the emulator. Unless you are using some specific features of the device such as a camera, you can expect your application to work without any issues on the emulator.

Figure 1 has a screenshot of "The Age of Empires" running inside the Microsoft Device Emulator. I have also successfully installed and used products like Microsoft Voice command to talk to my emulator.

In the next few sections, I will show you how easy it is to install an application on the device emulator using its capabilities to cradle with Active Sync.

ActiveSync Synchronization - It's Just Like a Device!
This was a new capability added to the Microsoft Device Emulator, which enables it to be treated like a real device in the eyes of ActiveSync. Once ActiveSync establishes a partnership to it, you can imagine the amazing number of scenarios that it opens up for you as a developer. You can install your application, simulate connectivity and Sync scenarios, and even use this feature to test complex scenarios like cradling and un-cradling support in your applications.

To cradle the emulator with ActiveSync, here is what is needed:

  1. Make sure you have modified the Connection Setting of Active Sync to enable the connection using DMA, as shown in Figure 2.
  2. Then start the tool called the Device Emulator Manager. If you are using Visual Studio, it's available on the Tools Menu. If you install the Device Emulator Standalone, you should run dvcemumanager.exe from C:\program files\Microsoft Device Emulator\1.0. Once you run it, you will see a list of available of emulators on your machine, as shown in Figure 3. If this list is empty you'll need to run the emulator manually to have it show up in the Manager (more details later).
  3. Depending on which emulator you wish to run and cradle, right-click on it and select connect.
  4. Once that emulator is running, you'll notice that the Device Emulator Manager indicates the running state of the emulator by a green play sign, At any given time, you can run as many emulators as you wish (depending on the availability of machine resources, of course).

    Figure 4 The Green Play sign indicates that emulator is running.

  5. Next, right-click one more time and select cradle. Once you select cradle, you'll notice ActiveSync spring into action and begin to establish a partnership with the emulator.
The possibilities now are endless. Your emulator is behaving like a real device. You can sync your email, test your application as if it was running on a real device connected to a PC, and even install software on it. I use this extensively to try applications before putting them on my real device. And with such a rich collection of emulators, as a developer, if you wish to test your application, you can try it very quickly on a variety of emulated devices like high/low resolution devices or devices with variation in screen displays and orientations, while saving yourselves loads of money not having to buy so many devices.

Where Is the Store Card?
The Device Emulator can also be used to emulate a storage card. It is actually very simple - you can map just about any existing folder on your development machine to be used as a storage card for the emulator. This can be done by pointing the "Shared Folder" property to any folder on your disk. Once that is set, all files on this folder will be available to the image running inside the emulator as if they were on a storage card.

The shared folder will show up as a Storage Card, (see Figure 4), when using the Files Manager. You can even install Device Applications on it when prompted during the install phase.

I have also used this feature to run Power Point files that were actually on my PC but rendered by Power Point on the Emulator. It is also interesting to observe that the emulator rotates automatically to show the presentation just like a real device would.

Another benefit of this feature comes in handy when you are building applications that require a large amount of static data (say a large SQL Mobile Database) that needs to be deployed as part of your application. In this case, you can put it in a Folder on your hard disk, share that folder with the emulator, then have your application access this data from the storage card, saving lots of time by deploying big files to the emulator.

Using the Command Line to Launch Emulator Images
While you can always use the Device Emulator Manager to start various emulator images, that capability depends on the existence of what is called a "Data Store" which is installed with Visual Studio 2005 and Platform Builder. This is information used by various tools to be aware of what's installed on your machine that can be used for device development. This is stored as a collection of files under \documents and settings\All Users\Application Data\Microsoft\corecon\1.0

In case of a standalone emulator (when you don't have a Data Store on that machine) you can launch any device emulator image using the command line as well.

When you start the emulator from the command line, almost every aspect of the device emulator can also be configured using the command line.

The simplest way to run a device emulator image would be to pass the name of the .bin file which is the emulator image file to DeviceEmulator.exe. For Example, running the following will launch the Pocket PC 2003 Second Edition VGA Emulator:

DeviceEmulator.exe PPC_2003_SE_VGA_WWE_ARMv4.bin

While some of these images are installed with Visual Studio 2005 or the Windows Mobile SDKs, you can also download and install standalone images from the following location: http://msdn.microsoft.com/windowsmobile/downloads/tools/install/default.aspx

When launching the emulator from the command line you can also specify to that emulator image how much memory you want to emulate by using /memsize parameter. Therefore, you can try your application in a variety of memory settings with ease.

My ALT+TAB Is Not Working and I Can't Take a Screenshot of the Emulator. Why?
Many people have asked me how I take screen shots of the emulator because when they try PrtSc or ALT+PrtSc, nothing seems to be captured. Also, they have reported that when the emulator has the focus, the ALT+TAB to another desktop application does not appear to work.

Well, no it is not a bug. It is how the emulator handles "Host Keys." If you look at the properties of the emulator (File->Configure), you will see that the host Key is set to Right Alt. Hence, if you want to take a screen shot of the emulator just use the RIGHT ALT Key along with the Print Screen button, or you can change the Host Key to Left Alt, which would cause things to work as expected. The host key allows you to use the keyboard for the development computer to control certain emulator actions, such as displaying its shortcut menu and predefining key combinations for operations such as shutdown, displaying file menu, and shortcut menus.


More Stories By Amit Chopra

Amit Chopra is the release program manager for the Visual Studio for
Devices team. He also manages the sustained engineering efforts for
eMbedded Visual C++ 4.0 and Visual Studio 2003. He can be contacted at achopra@microsoft.com.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.