APPENDIX A Setting Up Your Development Environment: A Quick- Step-Through

THIS MAY VERY WELL BE the shortest appendix in the history of publishing. Well, that may be an exaggeration, but this appendix will be short and to the point. The purpose here is to give you a feel for what you need to have installed to do a particular job in the world of .NET Compact Framework programming. The way to do that is to give you step-by-step instructions for what you need to do to get your environment up and running.

Install a Decent Operating System

By "decent," you might be thinking that I mean you shouldn't use Wmdows if you want a decent OS. Sorry, but no snide comments here! What I mean is you shouldn't use Windows 95 or . Visual Studio 2003 requires you to use one of the following operating systems:

• Wmdows XP Professional

• Wmdows Server 2003

• Wmdows 2000 Professional (SP3 or later)

• Wmdows 2000 Server (SP3 or later)

It's possible to use Wmdows XP Home Edition, but if you do, you won't be able to write or host ASP. NET pages or Web services.

907 Appendix A

Install Visual Studio .NET 2003

This should be obvious, but I want to be complete. It's also important to note that the .NET Compact Framework is part of the 2003 release ofVS .NET. The previous version, called the Smart Device Extensions, was provided as a separate add-on and installation to Visual Studio 1.0. For some "official" information on Visual Studio .NET 2003, you can check out either of these two Web sites:

• Visual Studio .NET Home Page-http:/ /msdn.microsoft.com/vstudio/

• Support Center for Visual Studio-http: I I support. microsoft. com/ default.aspx?scid=fh;EN-US;vsnet

Install ActiveSync

ActiveSync is the that synchronizes the data from your desktop com• puter to your PocketPC. Download the latest version of ActiveSync from http://www.microsoft.com/downloads/details.aspx?FamilyiD=67e9e87c-ca96-48b4- bSd4-f3e047ca5108&displaylang=en and install it on your computer. And really, that's all that is required to get started. The remaining tools you need are included in Visual Studio 2003. Of course, you may want to install some optional packages, and we'll discuss those next. You might also find a significant number of "toys" and other downloads interesting. The last portion of this appendix will contain links to some of those items.

Install SQL Server and SQL Server CE

If you don't plan on using SQL Server or SQL Server CE, then you don't have to worry about this section. But if you have a desire to use SQL CE by itself or to synchronize data with SQL Server, then this might be worth reading. With the problems that exist from a variety of hacking attempts and suc• cesses, everyone should have the latest service pack for SQL Server installed. At the time of writing, that is SP3. As was discussed in Chapter 11, installing SQL CE over SP3 can get a bit dicey. You can find a description of SP3 and a link to down• load it from this Web site: http: I lwww. microsoft. com/ sql/downloads/2000/ sp3. asp. Now, when you install SQL CE 2.0, you have to install client and server tools. If you installed SP3, then you can use the SQL CE installation for client tools, but you must install a service update on the server that is hosting liS. The following links point you to the important pages on the Microsoft Web sites that provide detailed information:

908 Setting Up Your Development Environment: A Quick Step-Through

• General SQL CE site-http: I /www. microsoft. com/ sql/ eel

• SQL CE 2.0 download site-http: I /www. microsoft. com/ sql/ eel downloads/ ce20.asp

• SQLEC service update-http: I /www.microsoft.com/sql/downloads/ce/sp3 .asp

When you install these upgrades, they will bring your Microsoft Data Access Components (MDAC) up to version 2. 7.

Install the eMbedded Tools

No, I don't know why Microsoft capitalizes the M and not the e. But I do know that you should install eMbedded Visual Tools 3.0 on your development machine. If you've previously used the embedded tools, you know that they include a vari• ety of tools that let you look at processes, files, and other details of the emulator or device. These tools aren't included in Visual Studio 2003, and in time you'll need them for debugging or curiosity, whichever comes first. You can set up the Tools menu in Visual Studio to launch the utilities from right inside the IDE. The SDKs that get installed with the tools also provide you the header files that can be used to build your own Declare or Dllimport statements to call unmanaged code. TWo versions of the eMbedded tools are currently available. Version 3.0 is the old standby that has been used for years to write applications for devices. The new kid on the block is eMbedded Visual C++ 4.0. This version, with Service Pack 2 installed, lets you target Windows CE 4.0, 4.1, and 4.2. At this time, Visual C++ 4.0 doesn't have an SDK to allow you to target the Pocket PC or Smartphone. Following are the URLs you'll need to access and learn more about the eMbedded Visual Tools:

• eMbedded Visual Tools Web site• http://msdn.microsoft.com/vstudio/device/embedded/default.aspx

• eMbedded Visual Tools 3.0- http://www.microsoft.com/downloads/details.aspx?Family!d=F663BF48-31EE- 4CBE-AACS-OAFFDSFB27DD&displaylang=en

• eMbedded Visual C++ 4.0- http://msdn.microsoft.com/vstudio/device/embedded/datasheet.aspx

• eMbedded Visual C++ 4.0 SP2-http: I /microsoft. com/ downloads/ details.aspx?Family!d=CE7F1AAA-54EB-4989-812B-7F95560SDCB8&display• lang=en

909 Appendix A

Once you digest all of the preceding Web sites and pages, you can get a gen• eral overview of application development for devices from the following site:

• Device development overview-http: I lmsdn. microsoft. comlvstudiol deviceloverview.aspx

Summary

This short appendix covers everything you need to get started. There are many sites that you can visit for downloads, help, and tools. Rather than add a large list of URLs here that you would have to type in by hand, you can get a list of links at either http: I lwww .larryroof. com or http: I lwww. forestsoftwaregroup. com. Appendix D tells you the exact location of these sites, from which you can also download ver• sions of the source code.

910 APPENDIX B Working with the Emulator

THE Focus OF THIS APPENDIX is to show you how to get the most out of the emula• tor. Before we get started, let me say that I'm not a big fan of emulators. Obviously, if you don't have a device, they're your only option. While I may grant this con• sideration for students, I can't see any possible scenario in which corporate or commercial developers would be without a device. The obvious and most important reason for testing on a device is that no matter how good a job the emulator does, it isn't a device. You don't interact with an emulator using a stylus; you use a keyboard and mouse. You don't hold it in your hand; it sits on your virtual desktop. It has different processor capabilities. With that said, I have to tell you that I have from time to time used the emu• lator. In situations where you don't want to hook up a device, such as on an airplane, the emulator is a nice alternative. Additionally, the emulator provided with the Smart Device Extensions is a vast improvement over previous Pocket PC emulators.

Launching the Emulator

You can launch the emulator in two ways: from within the Visual Studio .NET IDE and from the command prompt.

Launching the Emulator from Within VS .NET

There are two ways to launch the emulator from within the Visual Studio .NET IDE. The first way is as follows:

1. Start a Smart Device Extension project.

2. Select Pocket PC 2002 Emulator from the Deployment Device combo box, which is located on the toolbar.

3. Run your application.

911 AppendixB

The emulator will be automatically loaded in preparation to running your application. The second way to launch the emulator is to attempt to establish a connec• tion to the emulator from within the Visual Studio .NET IDE. This can be accomplished by clicking the Connect to Device button, which is located on the toolbar, or through the Connect to Device menu item on the Tools menu.

, ·1 ; TIP To speed the development process, it's best to leave the emula• tor open and running between builds and tests ofyour application. I've found that the slow start time of the emulator interferes with the build, test, refine, and repeat development process.

Launching the Emulator from the Command Prompt

To launch the Wmdows CE emulator from the command prompt, perform the following steps:

1. Open the command prompt.

2. Either define the path to, or navigate to, the directory where the emula• tor executable resides. By default, the emulator resides in the following directory: C:\Program Files\MicrosoftVisual Studio .NET 2003\ CompactFrameworkSDK\ConnectionManager\Bin.

3. Enter the command emulator, along with any command-line argu• ments, and press Enter. The emulator will start.

Table B-1 shows command line arguments for the emulator application.

Table B-1. Emulator Command Line Arguments

ARGUMENT DESCRIPTION /CEimage Represents the path to the operating system image to load into the emulator. The image must match the target device. This argument is required. /Ethernet Enables or disables an Ethernet adapter for use with the emulator. Acceptable values are none, shared, virtualswitch, or the MAC address of an adapter to use. /Skin Specifies the XML file defining the skin to use with the emulator. /Video Defines the resolution and bit depth for the emulator; for example, 240X320X 16.

912 Working with the Emulator

Default images, along with their skins, are included under the default folder hierarchy ofC:\Program Files\MicrosoftVisual Studio .NET 2003\ CompactFrameworkSDK\ConnectionManager\Bin\Images.

Running the Emulator Without a Network Connection

The emulators provided with Smart Device Extensions will not operate unless the development PC on which it's running has a network connection. If your PC doesn't have a network connection, you can still use the emulator by installing the Microsoft Loop back Network Adapter. This adapter simulates a network con• nection and effectively fools the emulator into running.

Installing a Loopback Adapter Under Windows 2000

Under Wmdows 2000, the process for installing the Microsoft Loop back Network Adapter is as follows:

1. From the , click Add/Remove Hardware.

2. On the Welcome page of the Add/Remove Hardware WIZard, click Next.

3. Select Add/Troubleshoot a device and click Next. The process will pause while your system is scanned for plug-and-play devices.

4. From the Choose a Hardware Device page, select Add a new device and click Next.

5. On the Find New Hardware page, select No, I want to select the hard• ware from a Hst and click Next.

6. From the Hardware Type page, select Network adapters and click Next. There will be a brief delay while a list of network adapters is generated.

7. On the Select Network Adapter page, first select Microsoft from the Manufacturers list box, then select Microsoft Loopback Adapter from the Network Adapter list box. Click the Next button.

8. From the Start Hardware Installation page click Next. The loopback adapter installs.

913 AppendixB

Configuring a Loopback Adapter Under Windows 2000

Like any network adapter, installing a loopback adapter is only half of the process. You also need to configure your new adapter. Perform the following steps to configure the loop back adapter:

1. From the Start menu, select Settings, then Network and Dial-up Connections, and finally Local Area Connection. The Local Area Connection Status dialog box displays.

2. Click the Properties button. The Local Area Connection Properties dia• log box displays.

CAUTION At this point, check to make sure that you're working with the right connection. The Connection Using field of this dia• log box should read Microsoft LoopbackAdapter.

3. Select Internet Protocol (TCP/IP) and click the Properties button. The Internet Protocol dialog box displays.

4. Configure the IP address properties.

5. Click the OK button to close the Internet Protocol dialog box.

6. Click the OK button to close the Local Area Connection Properties dialog box.

7. Click the Close button to close the Local Area Connection Status dialog box.

Configuring the Emulator

You can divide the topic of configuring the emulator into two categories: config• uring the "hardware" environment and configuring the instance of the Pocket PC operating system that's running in the emulator. I'm not going to discuss the process of configuring the operating system, as it's identical to how you would configure an actual device. Instead, in this section I'm going to focus on config• uring the hardware environment-that's to say, the virtual device on which the emulator runs.

914 Working with the Emulator Defining the Emulator's Hardware

The hardware configuration of the emulator is defined through the Visual Studio .NET IDE. This configuration defines the virtual device in which the emulator runs. In most cases, you can simply use the default settings, which define a device with 32 megabytes of RAM, a 240X320 screen with 16 bits of color depth (as shown in Figure B-1), and no COM or parallel ports.

Figure B-1. Default emulator settings

To alter the hardware configuration of the emulator, perform the follow• ing steps:

l. From within the Visual Studio .NET IDE, select Options from under the Tools menu.

2. Under the Devices folder of the Options dialog box, select Devices.

3. In the Devices list box, select Pocket PC 2002 Emulator, as shown in Figure B-l.

915 AppendixB

General + Devices Cl HTML Designer EJ Projects Windows Forms Designer [] XML Designer

Figure B-2. Specifying the device in the Devices list box

4. Click the Configure button.

5. The Configure Emulator Settings dialog box displays. Define your new emulator settings and click the OK button.

The Configure Emulator Settings dialog box has three tabs: Display, System, and Hardware. On the Display tab, you can specify the size and color depth of the emulator screen. From the System tab, you can define the emulator's mem• ory size and the host key, which provides a shortcut to emulator control features (see Figure B-3). The Hardware tab allows you to associate serial and parallel ports on your development PC to the emulator (see Figure B-4).

916 Working with the Emulator

Figure B-3. System tab settings

Figure B-4. Hardware tab settings

NOTE As with actual devices, the Pocket PC emulator is limited to 64 megabytes ofRAM. Even though the dialog box will allow you to set the amount of memory to 256 megabytes, the emulator will in fact only have 64 megabytes. This is a limitation of the Pocket PC 2002 operating system, which applies as well to the emulator.

' I ' TIP A common reamn to increase the memory size configuration of the emulator is to handle testing applications that make use of large SQL Server CE databases.

917 AppendixB Setting Up an ActiveSync Partnership

You may need to establish an ActiveSync connection to the emulator to test spe• cific features or functionality of your application. To create a connection to the emulator, your development PC needs at least two COM ports. The emulator and the development PC will each need a port for use with the ActiveSync connection. To establish the physical connection between your development PC and the emulator, perform the following steps:

1. Connect a null modem serial cable between the two serial ports.

2. Configure the emulator's hardware to include a serial port. This will be the emulator's ActiveSync connection.

3. On your PC, launch the ActiveSync application.

4. Under the File menu of the ActiveSync application, select Connection Settings.

5. On the Connection Settings dialog box, confirm that the setting Allow serial cable or Infrared connection to this COM port is selected.

6. Using the combo box, configure the COM port to one of the COM ports on which you connected the serial cable. Note that this should NOT be the port you added to the emulator.

7. Click the OK button to close the dialog box.

To establish a partnership between your development PC and the emulator, perform the following steps:

1. Start the emulator if necessary.

2. Press and hold the control key (CTRL) on your development PC.

3. In the emulator, click and hold on the clock in the upper-right comer of the title bar. After a brief pause, a shortcut menu displays.

4. From this menu, select Run.

5. In the Run dialog box, type repUog. The repllog executable is the device• side component of ActiveSync. It initiates the connection to a PC.

6. The ActiveSync module on your desktop PC will detect the emulator's attempt to connect. The New Partnership Wtzard will start. 918 Working with the Emulator

7. Complete the wizard, specifying the types of data to synchronize between the emulator and your development PC.

At this point, you have a functioning ActiveSync connection between the emulator and your development PC.

NOTE You should use ActiveSync version 3.6 or later when working with Smart Device Extensions and the .NET Compact Framework.

Changing the EmulatorJs Skin

This is another one of those things that falls into one of two categories: Either you have too much time on your hands or you're being paid by the hour. The emulator allows you to modify and customize the skins used by the emulator. If you're not already familiar with the term, skins define the appear• ance of an application. In this case, that application is the emulator. You define the skin for the emulator with an XML file. Listing B-1 shows an example of the default skin shipped with Visual Studio .NET. Through this file, you can configure the size and position of the emulator, the graphical images that define the interface, and tooltips.

' I , TIP You may choose to define custom tooltips in situations where your application is taking control over the hardware buttons.

Listing B-1. The Default Skin