If you have ever developed mobile applications, you know the importance of using emulators. Emulators allow you to test your application on different types of target platforms without needing to buy all these devices (which is not practical, as it is almost impossible to test your application on all makes and models). And so the emulator plays a very important part in the development cycle: How realistically can it emulate a real device? Are you able to drag and drop files onto the emulator? Can you install applications onto the emulator?
In this article, I will explore the emulator tools support that shipped with Windows Mobile 5.0 and Visual Studio 2005, and how you can use them to help in your mobile application development.
For this article, you will need the following:
Let's first start by using Visual Studio 2005 to create a Window Mobile 5.0 Pocket PC application. In Visual Studio 2005, go to File-->New Project, then select the Windows Mobile 5.0 Pocket PC project type and choose the Device Application template. Use the default name of DeviceApplication1 and click OK (see Figure 1).
Figure 1. Creating a new Windows Mobile 5.0 Pocket PC application
Once the project is created, you will see a default Windows Forms. We are not really interested in populating this form; what we are interested in is deploying it onto an emulator. Press F5 to debug the application. You will be asked to select a device to deploy your application (see Figure 2).
Figure 2. Choosing the device to deploy to
Select Windows Mobile 5.0 Pocket PC Emulator and click Deploy. The emulator will be launched and then a while later the application is deployed onto it (see Figure 3).
Note: If you are deploying a Windows Mobile application onto an emulator for the first time, it may take a while for the application to load. This is because Visual Studio 2005 is busy installing the .NET Compact Framework 2.0 class libraries onto the device. Subsequent deployment will be much faster. For your information, Windows Mobile 5.0 devices do not ship with .NET Compact Framework 2.0; they come with .NET Compact Framework 1.0 in ROM.
Figure 3. The emulator and the deployed application
In the last section, you saw how you can launch an emulator when you deploy an application. However, this is not always necessary. In Visual Studio 2005, there is now a Device Emulator Manager, which you'll find at Tools-->Device Emulator Manager (see Figure 4).
Figure 4. The Device Emulator Manager
In the Device Emulator Manager, you can right-click on the emulator that you want to launch and select Connect (see Figure 5). The selected emulator then is launched.
Figure 5. Selecting an emulator to launch
While you can launch an emulator and try out all the various features available in the platform, a much more useful feature is the ability to connect to the outside world. You may want to install a third-party application onto the emulator and see how it runs, or you may just need to transfer some files into and out of the emulator, onto your PC.
To do so, you need to use ActiveSync to connect to the emulator. First, in ActiveSync, go to File-->Connection Settings, and in the options for Allow Connections to One of the Following, select DMA (see Figure 6).
Figure 6. Configuring the connection settings in ActiveSync
Next, in the Device Emulator Manager, right-click on the emulator that is currently running and select Cradle. Once this is done, you will notice that ActiveSync now detects a connection from the emulator. The Synchronization Setup Wizard will now appear (see Figure 7). Click Next to proceed.
Figure 7. The ActiveSync Synchronization Wizard
As usual, you can configure your synchronization options (see Figure 8). Click Next and then Finish.
Figure 8. Configuring the synchronization options
ActiveSync should now be connected with your device (see Figure 9).
Figure 9. ActiveSync connected to the emulator
Once the emulator is connected to ActiveSync, you can explore the file system on the emulator by clicking the Explore button in ActiveSync. Figure 10 shows the location of the application (\Program Files\DeviceApplication1\DeviceApplication1.exe) that was deployed earlier.
Figure 10. Locating the application that was deployed earlier
Besides exploring the emulator's file system, you can now also install applications onto your emulator. You can now directly install Pocket PC applications onto your emulator (see Figure 11) through ActiveSync.
Figure 11. Installing an application onto the emulator through ActiveSync
Within minutes, I am having fun with some games on the emulator (see Figure 12). This ability to install applications onto the emulator is useful when you are building installation packages for your Windows Mobile 5.0 applications and you want to test them out without using a real device.
Figure 12. Playing games on the emulator
Beginning with Windows Mobile 2003 Second Edition, all devices support both the landscape and portrait screen orientations. As a Windows Mobile developer, it is your duty to ensure that your application is orientation-aware, and hence testing your application in both orientations is important.
In Start-->Settings (on the emulator; see Figure 13), select the System tab and the Screen item.
Figure 13. Launching the Screen application on the emulator
Select the Landscape orientation option (see Figure 14) and click OK. The emulator will be rotated according to the option selected.
Figure 14. Changing screen orientation
Visual Studio 2005 ships with a set of tools for Windows Mobile developers. You can find the tools by going to: Start-->Programs-->Microsoft Visual Studio 2005-->Visual Studio Remote Tools (see Figure 15).
Figure 15. Remote tools in Visual Studio 2005
The Remote File Viewer works similar to the Windows Explorer with which you are probably familiar. It allows you to view the file system on the selected device/emulator. When you start the Remote File Viewer, you will first be asked to select a Windows CE device/emulator (see Figure 16).
Figure 16. Selecting an emulator
The Remote File Viewer then displays the file system on the selected device/emulator. You can transfer files in and out of the device as well as delete files on the device (see Figure 17).
Figure 17. The Remote File Viewer
The Remote Heap Walker displays information about the following:
Figure 18. Processes running on a device
Figure 19. System memory used by a process
The Remote Process Viewer window displays information associated with each process running on a target device. You can use the Remote Process Viewer to kill processes that are running on a device/emulator (see Figure 20).
Figure 20. The Remote Process Viewer
The Remote Registry Editor displays the registry for a target device and enables you to add, delete, and modify registry keys and registry entries. You can also edit the registry entries on your local computer using the Remote Registry Editor (see Figure 21).
Figure 21. The Remote Registry Editor
The Remote Spy displays messages received by windows associated with applications running on a target device (see Figure 22). Remote Spy displays a list of the windows that are open on a target device. In a separate window, the tool displays information about the messages in the message queue for the selected window.
Figure 22. The Remote Spy
The Remote Zoom-in displays a screen image from a target device. This tool is useful for capturing screen shots of your device/emulator (see Figure 23).
Figure 23. The Remote Zoom-in
In this article, you have seen some of the techniques and tools that make your life as a mobile application developer easier. Learning how to use the emulator to your advantage will greatly increase your productivity and ensure that your application runs on various devices without problems.
Wei-Meng Lee (Microsoft MVP) http://weimenglee.blogspot.com is a technologist and founder of Developer Learning Solutions http://www.developerlearningsolutions.com, a technology company specializing in hands-on training on the latest Microsoft technologies.
Return to the Windows DevCenter.
Copyright © 2009 O'Reilly Media, Inc.