Export (0) Print
Expand All
Expand Minimize

Step by Step: Using Microsoft Device Emulator In-Depth in Your Application Development Experience

4/7/2010

Microsoft Corporation

February 2007

In this self-paced, hands-on lab (HOL), you’ll get a thorough experience of using Microsoft Device Emulator 1.0 both inside Microsoft Visual Studio 2005 as well as a stand-alone application. This HOL will take 1 hour to complete. (23 printed pages)

Microsoft Visual Studio 2005

Windows Mobile devices

Windows Mobile 2003 Second Edition and Windows Mobile 5.0 emulator images

The following applications are required to run this HOL:

  • Microsoft Windows XP Professional
  • Visual Studio 2005
    For exercises not involving the stand-alone Device Emulator, this HOL requires Visual Studio 2005 Standard, Professional, or Team System Editions. If you do not have the correct edition of Visual Studio 2005, find out how you can acquire it from the Visual Studio 2005 Developer Center.
  • Microsoft ActiveSync 4.0 or 4.1
    ActiveSync allows for connectivity between a Windows Mobile–based device and your computer. Earlier versions of ActiveSync are not supported.
    Download and install ActiveSync 4.0.
    Download and install ActiveSync 4.1.
  • Virtual Machine Network Driver
    The Virtual Machine Network (VMNet) Driver is required for the emulator to get Internet connectivity over TCP/IP independent of ActiveSync. You will use the VMNet Driver for some exercises involving the Device Emulator.
  • Windows Mobile 5.0 SDKs
    The Windows Mobile 5.0 SDKs for Pocket PC and Smartphone enable development for Windows Mobile–based devices in Visual Studio 2005. These SDKs contain the Windows Mobile 5.0 operating system images for Smartphone and Pocket PC.
    Download and install Windows Mobile 5.0 SDK for Pocket PC.
    Download and install Windows Mobile 5.0 SDK for Smartphone.
    Bb278114.note(en-us,MSDN.10).gifNote:
    If you used an emulator in a previous HOL, you should do a hard reset on the emulator before starting this HOL. (On the emulator, click File | Reset | Hard.)
    Bb278114.note(en-us,MSDN.10).gifNote:
    If you receive an error during deployment that indicates that the process or file is in use, this means that the program is still running on the emulator and must be closed before a new copy can be deployed and run. This error may appear anytime in the lab that you deploy the emulator.
  • Set up your computer
    Follow the directions in the Additional Information section to set up your computer for this HOL.

This self-paced, hands-on lab (HOL) is intended for all levels of developers who are writing device applications by using Visual Studio 2005 and professionals who are not developers (for example, marketing personnel, managers, support professionals, and engineers) and who work with the Device Emulator as an application deployment platform on which to run, test, demonstrate, and troubleshoot applications.

The objective of this lab is to use the Device Emulator 1.0 within Visual Studio 2005 and as a stand-alone application to launch and deploy applications.

In this HOL, you will perform the following exercises:

  • Launching the Device Emulator from Visual Studio 2005
  • Launching the Device Emulator as a stand-alone application
  • Cradling the Device Emulator
  • Enabling Internet connectivity from the emulator
  • Launching the Device Emulator from the command line
  • Using the emulator's states
  • Using configuration options in the emulator
  • Developing an application on the emulator
  • Mimicking exotic devices
  • Adding XML provisioning to the emulator during bootstrap
  • Understanding page alignment faults with ARM code

Exercise 1: Launching the Device Emulator from Visual Studio 2005

In this exercise, you will use Visual Studio 2005 to launch the Device Emulator as a target platform for application deployment. After you launch the emulator, you can cradle it by using ActiveSync similar to the way you would cradle a real Windows Mobile–based device.

There are three techniques to launch an emulator from Visual Studio 2005.

To launch the emulator from Visual Studio 2005 (Technique 1)
  1. On the desktop computer, click Start | All Programs | Microsoft Visual Studio 2005 | Microsoft Visual Studio 2005.

  2. In Visual Studio 2005, click Tools | Connect To Device.

    A list of devices and emulators appear in the list under Devices.

  3. Select Windows Mobile 5.0 Pocket PC Emulator, and then click Connect.

To launch the emulator from Visual Studio 2005 (Technique 2)
  1. On the desktop computer, click Start | All Programs | Microsoft Visual Studio 2005 | Microsoft Visual Studio 2005.

  2. In Visual Studio 2005, click Tools | Device Emulator Manager.

    A window with a list of devices and emulators appears.

  3. In the list, right-click Windows Mobile 5.0 Pocket PC Emulator, and then click Connect.

There is another way to launch the emulator from Visual Studio 2005. You can develop your own project or solution for your application, and then press F5 or click Build | Deploy Solution. This lab explains this technique in a later exercise that involves application deployment.

Exercise 2: Launching the Device Emulator as a Stand-Alone Application

In this exercise, you will learn how to launch the emulator as a stand-alone application.

To launch the emulator as a stand-alone application
  1. On the desktop computer, click Start | Run.

  2. In the Run dialog box, type cmd, and then click OK. A Command Prompt window opens.

  3. In the Command Prompt window, type cd "\Program Files\Microsoft Device Emulator\1.0", and then press ENTER.

  4. Type dvcemumanager.exe, and then press ENTER. The Device Emulator Manager opens.

  5. In the Device Emulator Manager, right-click Windows Mobile 5.0 Pocket PC Emulator, and then click Connect.

The stand-alone version of the Device Emulator Manager gives you a way to work with your emulator outside Visual Studio 2005.

Exercise 3: Cradling the Device Emulator

In this exercise, you will cradle the emulator. You can perform this exercise within Visual Studio 2005 or outside Visual Studio 2005 (if you launched the emulator as a stand-alone application by performing Exercise 2).

When you launch the emulator, it starts up like a physical device that is not cradled. To cradle the emulator, you need to use the Device Emulator Manager that you launched in Exercise 1.

To cradle the emulator
  1. Open Device Emulator Manager by following the "To launch the emulator from Visual Studio 2005 (Technique 2)" in Exercise 1. The emulator that you are connected to will be indicated by a green arrow.

  2. In Device Emulator Manger, right-click the name of the emulator, and then select Cradle, as shown in Figure 1.

    Bb278114.2c7b04c7-6e0c-4674-9463-0b3d3c51b669(en-us,MSDN.10).gif

    Figure 1. Cradling a device in Device Emulator Manager

    Bb278114.note(en-us,MSDN.10).gifNote:
    You need to have ActiveSync 4.0 or later installed on your desktop computer to be able to cradle the device. (Device Emulator Manager and the Device Emulator can work with ActiveSync 3.8, but Visual Studio 2005 only supports ActiveSync 4.0 and later).

    After you cradle the emulator, ActiveSync automatically detects that a new device has been connected. The ActiveSync icon in your system tray will turn green.

  3. Click OK if ActiveSync informs you that you will be able to synchronize only files, folders, and other items that Microsoft Outlook® does not use.

    You can either create a Guest partnership or a Standard partnership with the Device Emulator.

  4. Click Cancel when ActiveSync attempts to synchronize the emulator with your desktop computer (to retrieve Tasks, Calendar, Email, and Contacts). By clicking Cancel, you automatically set up a Guest partnership.

  5. Click OK to the additional ActiveSync messages.

  6. Keep the emulator open for Exercise 4.

Exercise 4: Enabling Internet Connectivity from the Emulator

In this exercise, you will use a cradled emulator just like a real device to access the Internet.

To access the Internet from a cradled emulator
  1. After ActiveSync is in the Connected state, the emulator should have network connectivity.

    Bb278114.note(en-us,MSDN.10).gifNote:
    If you are unable to access the Internet or an Intranet site, it might be the emulator's proxy settings.
  2. On the emulator, click Start | Settings, and then click the Connections tab. Click Connections, and then click the Advanced tab.

  3. Click Select Networks.

  4. In the Internet connections box, choose My ISP.

  5. In the Programs that connect to a private network box, choose My ISP.

  6. Click OK or the Close button until you close all of the dialog boxes.

    Bb278114.note(en-us,MSDN.10).gifNote:
    When you choose My ISP, you do not need to configure a proxy server for the emulator. ActiveSync on the desktop computer uses the desktop computer's proxy server settings in Microsoft Internet Explorer®.

    You can now access Internet sites, for example, www.microsoft.com, from Internet Explorer on the emulator, as shown in Figure 2.

    Bb278114.11f83dea-ab2c-4f39-97ca-7e909c60554d(en-us,MSDN.10).gif

    Figure 2. Viewing Web pages on the emulator

  7. Keep the emulator open for Exercise 5.

There is another way to enable network connectivity in the emulator without using ActiveSync—using the Virtual Machine Network Driver. The Virtual Machine Network Driver is explained more in Exercise 12.

Exercise 5: Launching the Device Emulator from the Command Line

In this exercise, you will launch the Device Emulator from the command prompt and choose a list of options.

To launch the emulator from the Command Prompt window
  1. Open a Command Prompt window on the desktop computer by clicking Start | Run.

  2. In the Run dialog box, type cmd, and then click OK. A Command Prompt window opens.

  3. In the Command Prompt window, type cd "\Program Files\Microsoft Device Emulator\1.0", and then press ENTER.

  4. Type DeviceEmulator.exe /?. The Device Emulator message appears, as shown in Figure 3. This message shows you various command line options and an explanation for each of them.

    Bb278114.ad2cd778-6bad-4e3a-b717-c0ac0534e6f1(en-us,MSDN.10).gif

    Figure 3. Device Emulator message with command line options and explanations

  5. After you review the options, click OK to close the message.

    You do not have to use each of the command line options. Figure 3 is meant to give you details about all of the options that are available from the command line.

In Exercise 6, you will use some of the key command line options, such as specifying a saved state file.

Exercise 6: Using the Emulator's States

In this exercise, you will learn about operating system saved states and booting from them. When you click Connect on an emulator in Device Emulator Manager, it always tries to boot from the last known saved state.

A saved state file contains all RAM, ROM, and settings information from the Device Emulator and has the extension .dess (Device Emulator Saved State). The .dess file is the only file necessary to restore a saved state. The .dess extension is registered at setup, so double-clicking a .dess file launches the Device Emulator with the state saved in that file.

To save an emulator's state
  • In the emulator's window, click File | Save State and Exit to save the state. This step saves the current state to the current Virtual Machine Identifier (VMID) of the emulator. It generates a saved-state file (.dess) by default in the following folder: C:\Documents and Settings\HOL\Application Data\Microsoft\Device Emulator, where HOL may be replaced by the name of the user who is currently logged in to Windows. Global saved-state files are located in C:\Documents and Settings\All Users\Application Data\Microsoft\Device Emulator.

    Bb278114.note(en-us,MSDN.10).gifNote:
    You are also prompted to save state whenever you close the emulator.
To restore a previous saved state
  1. In Device Emulator Manager, click File | Restore Image.

  2. In the Select Image to Restore dialog box, browse to C:\Documents and Settings\HOL\Application Data\Microsoft\Device Emulator (substituting your user name for HOL if necessary).

  3. Right-click anywhere in the blank explorer area (in other words, do not click a file), and then click View | Details.

  4. Examine the Date Modified of the saved state (.dess) files. The file with the latest date and time should be the file that you saved in the "To save an emulator's state" procedure.

  5. Note the VMID (the part of the file name before the .dess extension), and then double-click the file to open the emulator with the saved state. The device is in the state that you last saved it in.

  6. Click File | Exit. This time, click No when prompted to save the emulator’s state.

In Exercise 5, you learned about using the command line options to launch the Device Emulator. In the next procedure, you will try to launch the emulator by using one of the saved state files that is present in the HOL (or current user) directory of your computer. You will also use some other options, such as keeping the emulator always on top and setting memory size.

For the following procedure, pretend that your saved state file is {66BAB26C-BA30-4C84-BD02-98E06BD4353E}.dess.

To use the command line option to pick a saved state file
  1. Open a Command Prompt window on the desktop computer by clicking Start | Run.

  2. In the Run dialog box, type cmd, and then click OK. A Command Prompt window opens.

  3. In the Command Prompt window, type cd "\Program Files\Microsoft Device Emulator\1.0", and then press ENTER.

  4. Type DeviceEmulator.exe /s “\Documents and Settings\HOL\Application Data\Microsoft\Device Emulator\{66BAB26C-BA30-4C84-BD02-98E06BD4353E}.dess” /a /memsize 128, and then press ENTER.

    Bb278114.note(en-us,MSDN.10).gifNote:
    You may need to replace HOL with your user name. Also, be sure to replace the VMID with the VMID that you noted in Step 5 of the "To restore a previous saved state" procedure.

    The /s option specifies the fully qualified path to the saved state file. The /a option keeps the emulator on top, and /memsize sets the emulated memory size in megabytes.

  5. Keep the emulator open for Exercise 7.

Exercise 7: Using Configuration Options in the Emulator

In this exercise, you will learn more about the various configuration options in the emulator’s user interface.

To launch the emulator’s properties
  • On the emulator's window, click File | Configure to open the Emulator Properties dialog box, as shown in Figure 4.

    Bb278114.942a2aa9-6f8f-4f5f-9a05-c312791969f2(en-us,MSDN.10).gif

    Figure 4. Emulator Properties dialog box

The next two procedures explore the options in the General tab in the Emulator Properties dialog box.

To specify a host key
  1. In the Emulator Properties dialog box, click the General tab.

  2. Under Host key, choose your desired host key.

    The host key allows you to use the keyboard for the development computer to control certain emulator actions, such as displaying its shortcut menu. You implement this technique by predefining key combinations for operations such as shutdown, displaying a file's menu, and shortcut menus.

To share your desktop computer's folders
  1. In the Emulator Properties dialog box, click the General tab.

  2. Under the Shared folder, type the path and folder name of the directory that you want to use.

    The folder that you select appears as a storage card in your device. The emulator responds to the shared folder storage card as if it were a real device.

    On the Display tab, you can perform simple operations, such as changing skin orientation (specifying the desired degrees of rotation), zooming, enabling the always-on-top option, and enabling Tooltips. The next procedure explores ways to customize the emulator's skin by using the options in the Display tab in the Emulator Properties dialog box.

To customize the emulator's skin
  1. In the Emulator Properties dialog box, click the Display tab.

  2. Select the skin option.

  3. Click the Ellipses button, and then browse to the skin file of your choice to specify your own skin file.

    To customize the emulator's skin, you need three graphic files and an XML schema definition:

    • The first image is a bitmap (.bmp) or Portable Network Graphics (.png) file that shows the default appearance of the emulator's skin.
    • The second image is a .bmp or .png file that shows the appearance of the emulator's skin with all of the buttons pressed.
    • The third image is a .bmp or .png file that shows the area of each button filled with a single unique color. If you want the appearance of each button to change independently of the other buttons in the emulator's skin, use a different color to fill the area for each button.
    • The .xml skin definition file. The schema definition is shown in Figure 5.
      Bb278114.8369cea9-f48e-4001-903a-7414779a6fe7(en-us,MSDN.10).gif

      Figure 5. The schema definition for the .xml skin definition file
    • The up.bmp file specifies the normal art file for the emulator's skin, which is required. This normal art file specifies the size of the window for the emulator and the appearance of the emulator's skin. The map.bmp file specifies the mapping file for the emulator's skin. It is an optional file that defines the regions that the buttons occupy. The down.bmp file specifies the down art file for the emulator's skin. This is optional file that specifies the appearance of the buttons on the emulator's skin when the buttons are pressed down. You can save the three .bmp or .png files and the .xml file to one single directory.

    On the Display tab in the Emulator Properties dialog box, you can also pick your custom-created skin .xml file to see the emulator configured with the new skin.

    To get a better idea about the image files and XML, browse to C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Deviceemulation\, which is where the Windows Mobile SDK installs. You will find several device-configuration–specific directories, each of which contains .png and .xml files that define the skins for that configuration.

  4. When you are finished, close the emulator, but do not save its state.

  5. Close Device Emulator Manager.

Exercise 8: Deploying an Application on the Emulator

In this exercise, you will create a Visual Studio 2005 application and deploy it on the Device Emulator. The application itself is very simple, but the purpose of the exercise is to demonstrate to you the usefulness of the emulator as a target platform.

To deploy a Visual Studio 2005 application on the emulator
  1. Open Visual Studio 2005, and then click File | New Project.

  2. Under Project Types, select Visual C# | Smart Device | Windows Mobile 5.0 Pocket PC.

  3. Under Templates, select Device Application.

  4. Keep the default application name.

  5. Change the Location to C:\Program Files\Windows Mobile Developer Samples\HOLs\MEDC06_HOL315, and then click OK.

    Visual Studio 2005 creates the standard project for you. The first page on the project is the form designer (which is based on the Pocket PC project that you selected).

    Bb278114.note(en-us,MSDN.10).gifNote:
    You can toggle between the form designer and Code view by right-clicking the form designer, and then selecting the first option.

    Your simple application involves three controls: a text box, a label, and a button. You can see these standard controls in the Toolbox. (If the Toolbox is not in view, you can have it shown and docked from the View menu.)

  6. Drag a Textbox, a Label, and a Button control to the application’s form designer (Form1.cs), as shown in Figure 6.

    Bb278114.c930466d-860a-42de-aa70-9c73ae0cc422(en-us,MSDN.10).gif

    Figure 6. Adding controls to a Pocket PC project

  7. Rename the button by changing its Text property to Copy it.

  8. Keep the text box and label names as their defaults.

    Now that you have designed your form, you need to add the code.

  9. Double-click the button to add code to its click event. Visual Studio 2005 places the cursor in the button1_Click method for the Form1.cs code file.

  10. Add the following code this method.

    label1.Text = textBox1.Text + "\n" + label1.Text;
    textBox1.Text = "";
    

    The first line of code places the current text in the text box to the beginning of the label. A new line is used to separate the new text. The next line is added to clear the text in the text box.

  11. Leave the code that handles text in the text box unchanged, as shown in the following code example.

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    
    }
    
  12. In Visual Studio, click Build | Build Solution to compile the application. Your application should compile without any errors.

    You are ready to run or deploy the application. Next, you will test it on your Windows Mobile 5.0 Pocket PC Emulator.

  13. Press F5 or click Debug | Start Debugging. The Deploy dialog box appears, as shown in Figure 7.

    Bb278114.e105e746-4aa8-4e05-9684-2ec6825e9408(en-us,MSDN.10).gif

    Figure 7. Deploy dialog box

  14. Select Windows Mobile 5.0 Pocket PC Emulator, and then click Deploy.

  15. Wait until your application and any required runtimes are deployed to the emulator. When the emulator firsts loads, it will look like a standard Window Mobile 5.0–based Pocket PC display until the application loads.

    In the application, if you enter text into the text box, and then click Copy it, the text is copied to the Label control.

  16. Close the emulator, and save the state of the emulator when you are prompted to do so.

In this exercise, you saw how you can configure your application to run on the emulator of your choice and get the same look and feel as a real device.

Exercise 9: Mimicking Exotic Devices

In this exercise, you will learn how to use the emulator to mimic exotic devices. You will learn how to turn off skins and set the display size and color depth manually. This exercise allows you to use the emulator to boost your test coverage, test real hardware configurations, and deal with uncommon or exceptional devices.

To use the emulator to mimic exotic devices
  1. In Visual Studio, click Tools | Options | Device Tools | Devices.

  2. In the Devices box, select Windows Mobile 5.0 Pocket PC Emulator.

  3. Click Save As, and then save this emulator to My Test Emulator.

  4. Click OK. The newly saved emulator appears in the list.

  5. Select the newly saved emulator, and then click Properties.

  6. In the Properties dialog box, click Emulator Options.

  7. In the Emulator Properties dialog box, click the Display tab.

  8. Turn off the skin by selecting Video.

  9. Set Screen width to 240, Screen height to 240, and Color depth to 32 bits per pixel. Click OK on the three dialog boxes in succession. (You can also change the orientation.)

  10. In Visual Studio, click Tools | Device Emulator Manager to open the Device Emulator Manager.

  11. Click Refresh. You will see the newly configured emulator is in the list under the appropriate platform node.

  12. Right-click the newly configured emulator, and then click Connect.

  13. Observe the changes that you applied to mimic a device with a square resolution.

  14. Close the emulator window. There is no need to save the state of the emulator.

  15. Close Device Emulator Manager.

Exercise 10: Adding XML Provisioning to the Emulator During Bootstrap

In this exercise, you will learn how to use the Visual Studio core connectivity bootstrap to push special files on to the emulator. You can use the XML provisioning feature to preconfigure your emulator to add Internet Explorer favorites, have the correct Internet Explorer proxy server set up, add registry keys, and set time zones and locales. When you first open an application on the emulator, Visual Studio establishes a connection to the emulator and provisions the emulator with certain executable files and dynamic-link library files that are needed on the device to receive and execute the application. This process of copying the Visual Studio device-specific binaries is called the bootstrap phase.

You will see how you can push a custom XML provisioning file to the emulator during the bootstrap phase as the emulator launches. This XML is parsed on the device by a process called DMProcessConfigXML. In this exercise, you will use the Visual Studio 2005 XML provisioning feature to configure the emulator on startup. For simplicity, you will use XML provisioning to create a new Internet Explorer favorite on the emulator.

To view the existing list of Internet Explorer favorites
  1. If the Windows Mobile 5.0 Pocket PC emulator is not already running, open it using Device Emulator Manager.

  2. In the emulator, click Start | Internet Explorer to open Internet Explorer.

  3. In Internet Explorer, click Menu | Favorites to open the list of favorites, as shown in Figure 8.

    Bb278114.6984a6f4-b60a-461c-bdf7-909e3150712d(en-us,MSDN.10).gif

    Figure 8. Internet Explorer default list of favorites

  4. Note the current list of favorites and how many there are.

  5. Click OK to close the Favorites list.

  6. On the emulator's window, click File | Save State and Exit.

To provision the emulator with a new Internet Explorer favorite
  1. Create an XML provisioning file by opening Notepad and by adding the following code. This XML provisioning file creates a new Internet Explorer (browser) favorite named MSDN Mobility and points to the URL, http://msdn.microsoft.com/mobility.

    <wap-provisioningdoc>
        <characteristic type='BrowserFavorite'>
            <characteristic type='MSDN Mobility'>
                <parm name='URL' value='http://msdn.microsoft.com/mobility'/>
            </characteristic>
        </characteristic>
    </wap-provisioningdoc>
    
  2. Save the file as IEFavorite.xml on your computer at the location of your choice.

  3. In Visual Studio 2005, click Tools | Options | Device Tools | Devices.

  4. In the Options dialog box, under Devices, select Windows Mobile 5.0 Pocket PC Emulator, and then click Properties.

  5. On the Windows Mobile 5.0 Pocket PC Emulator Properties dialog box, click the Configure button next to Device Emulation Startup Provider.

  6. On the Configure Emulation Bootstrapper dialog box, click the Ellipses button, and then navigate to and select the IEFavorite.xml file.

  7. Click OK to close the Configure Emulation Bootstrapper dialog box.

  8. Click OK to close the Windows Mobile 5.0 Pocket PC Emulator Properties dialog box.

  9. Clock OK to close the Options dialog box.

  10. Using Device Emulator Manager, launch the Windows Mobile 5.0 Pocket PC Emulator.

Bb278114.note(en-us,MSDN.10).gifNote:
You may notice a short delay when the emulator opens because the XML provisioning file is transferred to the emulator.
To view the updated list of Internet Explorer favorites
  1. If Internet Explorer is not already open in the emulator, open it by clicking Start | Internet Explorer.

  2. In Internet Explorer, open the list of favorites by clicking Menu | Favorites, as shown in Figure 9.

    Bb278114.5eb02664-a1ff-4766-8ded-6885ee5d4f7d(en-us,MSDN.10).gif

    Figure 9. Internet Explorer favorites with the newly added favorite, MSDN Mobility

  3. Notice that the MSDN Mobility favorite defined in the XML provisioning file now exists.

  4. Close the Favorites list by clicking ok.

  5. Close the Windows Mobile 5.0 Pocket PC emulator by clicking File | Save State and Exit.

Bb278114.note(en-us,MSDN.10).gifNote:
The XML Provisioning feature works with all of the emulators. If time permits, feel free to repeat the exercise using one of the Pocket PC 2003 Second Edition emulators or one of the Smartphone emulators.
Bb278114.note(en-us,MSDN.10).gifNote:
Each of the entries within the XML provisioning file is processed by what are called configuration service providers. For a listing of configuration service providers and their respective schemas, see Configuration Service Provider Reference for Windows Mobile–based Devices.

Exercise 11: Understanding Page Alignment Faults with ARM Code

Because the emulator emulates the ARM CPU and executes instructions that are written for the ARM architecture, it is always interesting to learn about the kinds of bugs that you should expect to discover in your code as the result of running the Device Emulator versus an x86-based computer.

In this exercise, you will write an x86 Windows-based application that works fine on the x86 architecture, but will generate an alignment fault on ARM.

To write code that generates an alignment fault on ARM
  1. Open Visual Studio 2005, and then create a new project by clicking File | New Project.

  2. Under Project Types, select Visual C# | Smart Device.

  3. In the right pane, select Win32 Smart Device Project.

  4. Select all of the default options (for example, you can choose Pocket PC 2003 as the target device).

    The project editor opens.

  5. Comment out the all of the code within the WinMain function.

  6. Add the following code to declare a five-element character array, initialize it and declare another char* p. You should also assign the array address to p in WinMain.

    char array[5] = {0, 1, 2, 3, 4};
    char *p;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine, int       nCmdShow)
    {
        p = array;
        return *(int*)&p[1];
    }
    
  7. Compile and run this code on a Pocket PC 2003 Second Edition emulator.

    You will notice that the code, when executing, will hit a page alignment fault (even though such code is legal on an x86 platform). This page alignment fault is because the ARM processors cannot access unaligned data in memory (for example, it cannot read from an address that is not a multiple of 4). The x86, however, allows unaligned access albeit at a performance penalty.

  8. Click Continue to stop debugging the application.

In this lab, you performed the following exercises:

  • Launching the Device Emulator from Visual Studio 2005
  • Launching the Device Emulator as a stand-alone application
  • Cradling the Device Emulator
  • Enabling Internet connectivity from the emulator
  • Launching the Device Emulator from the command line
  • Using the emulator's states
  • Using configuration options in the emulator
  • Developing an application on the emulator
  • Mimicking exotic devices
  • Adding XML provisioning to the emulator during bootstrap
  • Understanding page alignment faults with ARM code

Terminating an Application That Is Running on a Device or Emulator

This appendix describes how to terminate an application that is running on a device or emulator. This is useful for cases where an application has been started without having the debugger attached and the application needs to be terminated so a new copy of the application can be deployed. You will terminate the application by using the Remote Process Viewer remote tool in Visual Studio.

Before you can terminate a process, you need to know the name of the executable file. In most cases, this is the same name as the Visual Studio project. If you are uncertain about the name of the executable file, you can find it in the project's properties.

To terminate an application that is running on a device or emulator by using the Remote Process Viewer remote tool
  1. In Visual Studio, select Project | xxx Properties, where xxx represents the name of the current project.

  2. Note the value in the Configuration Properties | Linker | General | Output File field. This is the name that the executable file will be running as on the device or emulator.

  3. Close the Properties dialog box.

    Now, you can terminate the process.

  4. On the desktop computer, click Start | Microsoft Visual Studio 2005 | Visual Studio Remote Tools | Remote Process Viewer.

  5. When prompted by the Select a Windows CE Device dialog box, select the emulator or device where the application is running, as shown in Figure 10, and then click OK.

    Bb278114.104db110-938a-4bfd-bb58-5acb569e2011(en-us,MSDN.10).gif

    Figure 10. Select a Windows CE Device dialog box

  6. After the connection to the emulator or device completes, select the application that you want to terminate in the top pane of the Remote Process Viewer, as shown in Figure 11.

    Bb278114.2ccda96f-7006-4bd7-88e9-959aa3805167(en-us,MSDN.10).gif

    Figure 11. Selecting the application to terminate

    You may need to widen the Process column (the leftmost column) to fully view the process names.

  7. In Windows CE Remote Process Viewer, click File | Terminate Process to terminate the process.

    Bb278114.note(en-us,MSDN.10).gifNote:
    Be certain that the correct process is selected before you click Terminate Process. Terminating the incorrect process may render the device or emulator unusable, requiring it to be reset before you can use it again.
  8. Verify that the process is terminated by selecting Target | Refresh. Scroll to the top pane of Windows CE Remote Process Viewer again. If the application name still appears, the process was not terminated, and you need to repeat these steps.

    Bb278114.note(en-us,MSDN.10).gifNote:
    Most processes terminate in one try; however, depending on the state of the application, terminating a process occasionally takes two attempts.
Show:
© 2014 Microsoft