|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
This article has been provided courtesy of MSDN. SummaryLearn about developing robust smart client device applications with the .NET Compact Framework 1.0 and Visual Studio .NET 2003. (34 printed pages) Contents
IntroductionMicrosoft developed the .NET Compact Framework with one intention in mind: to build applications. I am talking about applications that display, gather, process and forward information, those applications that give users a reason to carry a device. While they typically will have an interface, they do not require one. The data that they are working with might be local, might be remote, or some combination of both. The .NET Compact Framework simplifies application development on smart devices. Currently this includes the Pocket PC, Pocket PC 2002, Pocket PC Phone Edition and other devices running Windows CE.NET 4.1 or later. You will need Visual Studio .NET 2003 to build applications that target the .NET Compact Framework. You can build applications using either Visual C# .NET, Visual Basic .NET, or both. The .NET Compact Framework has two main components: the common language runtime and the .NET Compact Framework class library. The runtime is the foundation of the .NET Compact Framework. It is responsible for managing code at execution time, providing core services such as memory management and thread management while enforcing code safety and accuracy. Code that targets the runtime is known as managed code; code that does not target the runtime, as is the case with eMbedded Visual C++, is known as unmanaged, or native code. The .NET Compact Framework class library is a collection of reusable classes that you can use to quickly and easily develop applications. This framework was designed with porting in mind, whether to Microsoft or third-party platforms. What does this mean to you? Simply that the coding techniques and the applications you create today to run on a Pocket PC could run on other platforms, such as a cell phone or another vendor's PDA, if a version of the .NET Compact Framework was created for that platform. Common Language RuntimeThe common language runtime provides a code-execution environment that manages code targeting the .NET Compact Framework. Code management can take the form of memory management, thread management, security management, code verification and compilation and other system services. The runtime is designed to enhance performance. It uses just-in-time (JIT) compiling, which enables managed code to run in the native machine language of the platform on which your application is running. This allows you to create applications that can target a variety of platforms and not have to worry about recompiling or generating executables that target each specific platform. Even though your mobile application is written in Visual Basic .NET or C# .NET, and as such is managed code, you are still able to incorporate functions and subroutines stored externally in dynamic link libraries (DLLs), including the Windows CE APIs. The .NET Compact Framework provides the data types and support for structures to allow you to easily incorporate functions from the Windows CE APIs into your application. .NET Compact Framework Class LibraryThe .NET Compact Framework class library is a collection of reusable classes that tightly integrate with the common language runtime. Your applications leverage these libraries to derive functionality. As you would expect from an object-oriented class library, the .NET Compact Framework types enable you to accomplish a range of common programming tasks, including tasks such as interface design, leveraging XML, database access, thread management and file I/O. Following is a list of common functionality available through the .NET Compact Framework. Form-related ClassesThe .NET Compact Framework implements a subset of the The implementation of Windows Forms under the .NET Compact Framework includes support for forms, most controls found in the .NET Framework, hosting third-party controls, bitmaps and menus. Table 1 lists the controls included with the .NET Compact Framework. Table 1. Controls included with the .NET Compact Framework
Since the .NET Compact Framework is a subset of the full .NET Framework, the included controls have a subset of their desktop cousins' functionality. Due to size and performance considerations, some control properties, methods and events have been omitted from .NET Compact Framework controls. With a little coding, you can implement these omitted features yourself as needed. This is because the .NET Compact Framework allows you to create your own controls by inheritance from the base control class. From this foundation, you can add your own properties, methods and events to create just the control you need. Data and XML ClassesThe .NET Compact Framework includes a set of classes that allow you to easily incorporate data (whether from a relational or non-relational data source), including XML content, into your mobile applications. These classes are defined under the Web ServicesThe .NET Framework is much about Web services. In the .NET Compact Framework These XML Web service clients can be either synchronous or asynchronous. Creating an XML Web service client that targets the .NET Compact Framework is easy. The Visual Studio .NET IDE does much of the work for you. GDI SupportThe .NET Compact Framework provides support for the basic GDI drawing elements including bitmaps, brushes, fonts, icons and pens through the Base ClassesThe .NET Compact Framework provides a robust set of base classes that expose a wide-range of functionality for use by developers. This underlying infrastructure enables you to write rich .NET applications including being able to create multi-threaded applications ( IrDA SupportWindows CE devices, such as the Pocket PC and Pocket PC 2002, include infrared (IR) communication capabilities. In support of this, the .NET Compact Framework includes classes that allow you to leverage IR communication from within your application. These classes are part of the Bluetooth SupportThe .NET Compact Framework does not natively provide support for Bluetooth. You can access most third-party Pocket PC implementations of Bluetooth via either serial port communications or through a provider's API. Visual Basic SupportVisual Basic .NET makes liberal use of helper functions that are located in a Visual Basic Helper library. The .NET Compact Framework includes a subset of these functions as well. These functions are considered by Visual Basic developers to be a core part of the language, which is the reason for their inclusion. If you are a Visual Basic or eMbedded Visual Basic developer converting over to the .NET Compact Framework, this means that many of the Visual Basic language functions you are used to working with will be available to you in Visual Basic .NET. Ala Carte FeaturesTo conserve resources on the target device, Microsoft divided the .NET Compact Framework into logical components. By delivering components as separate DLLs—or assemblies as they are referred to within the .NET Compact Framework—Microsoft gives you the option of picking and choosing the features you need, and only those features that your target device has the space to hold. An example of this is the Another example of the .NET Compact Framework ala carte approach is SQL Server CE components, delivered in a set of DLLs totaling slightly over 1MB in size. Unless you explicitly add a reference to the Features Missing from the .NET Compact FrameworkSome serious trimming had to be made to the .NET Framework so that it could fit into the operating constraints of Windows CE. The most notable .NET Framework features that did not make it into the .NET Compact Framework are the subject of this section. Method OverloadsOverloading a method provides alternative ways to call that method. It also increases the size of the Framework. Because of this, the .NET Compact Framework trimmed the overloads from almost all methods. What this means to you is two-fold. First, there is a good chance that a particular method overload you used with a desktop application will not be available when developing .NET Compact Framework-based applications. Second, when you read the documentation, pay close attention to whether or not a method is supported by the .NET Compact Framework. Missing ControlsA number of .NET Framework controls did not make their way into the .NET Compact Framework. The absence of most of these controls is insignificant to mobile developers. Since printing has such a limited role in mobile applications, removing the whole family of print-related controls is not an issue. That takes care of the CrystalReportViewer, PageSetupDialog, PrintDialog, PrintDocument, PrintPreviewControl and PrintPreviewDialog controls. You can replace many of the missing dialogs with your own dialogs or by accessing system dialogs directly using the Windows CE API. Third-party controls are already becoming available to fill in for the controls that were left out of the .NET Compact Framework. For a list of third-party .NET Compact Framework controls see the references at the end of this article. XML FunctionalityAs much as the .NET Compact Framework offers in the way of XML, an equal amount of functionality was trimmed. The key missing XML-related component is the The .NET Compact Framework is missing another key XML component, Extensible Stylesheet Language Transformation, or XSLT. With XSLT, you can convert an XML document into different formats. On an XML-related note, the .NET Compact Framework does not currently provide support for developing device-based XML Web services. Database SupportThe .NET Compact Framework offers a robust set of data-related tools. Local database support is provided for SQL Server CE. On the server side, the .NET Compact Framework provides support for SQL Server. Note that there is a third party who provides a .NET Compact Framework component for working with Pocket Access databases. For more information, see the references at the end of this article. Binary SerializationDue to size and performance considerations both the Access to the Windows RegistryThe .NET Framework has the Microsoft.Win32.Registry namespace, which makes it easy to work with the Windows registry from an application. Obviously, this namespace was not included in the .NET Compact Framework, because it relates to Win32, not Windows CE. You may access the Windows CE registry by invoking the relevant Windows APIs. Leveraging COM ComponentsIncorporating COM objects into a .NET Compact Framework-based application is a two-step process. First, you must write an unmanaged—that is to say eMbedded Visual C++—DLL wrapper that exposes the COM object. Depending upon the complexity of the COM object, this may be anything from simple to extremely complicated. Second, you must use PInvoke to access your DLL wrapper. Luckily, the development community has already begun work on accessing the more commonly used COM components, several of which are included in the references at the end of this article. SecurityThe .NET Compact Framework does not secure access to unmanaged code. Any application can call any system or non-system API. There is currently no role-based security with the .NET Compact Framework. The principal object has no understanding of known identity or known role. XML Web ServicesThe most notable exclusion from the .NET Compact Framework XML Web service capabilities is the ability to use cookies. Cookies are widely used to maintain state on the server between calls from a client. While the use of cookies in Web services is not as prevalent as their use on Web sites, they are still in use. The .NET Compact Framework offers limited cryptographic abilities with respect to Web services. PrintingThe .NET Compact Framework provides no support for printing. There is no easy way to interact with either network printers or external printers via IR. The workaround for accessing network printers is to build a server-based application, which accepts and prints jobs submitted by your mobile application. You can send output through the IR port directly to IR-enabled printers. You use the GDI+Windows CE does not natively support GDI+, so GDI+ related functionality was removed from .NET Compact Framework. RemotingThe first release of the .NET Compact Framework does not support remoting. Developing with Visual Studio .NET 2003Visual Studio .NET 2003 provides a robust development environment for creating applications that target the .NET Compact Framework. Included with Visual Studio .NET is a set of pre-built device profiles. A device profile contains information necessary to build applications that target specific devices. With Visual Studio .NET, there are profiles that enable you to create applications for the Pocket PC, Pocket PC 2002, and Windows CE .NET 4.1 and later. These profiles allow you to create applications that include Windows Forms and ADO.NET, and offer the ability to consume Web services. Profiles may be device-specific, such as targeting the Pocket PC, less-specific platforms that target the Windows CE platform in general, or generic profiles that target any platform to which the .NET Compact Framework has been ported. Visual Studio .NET supports device kits (formerly known as SDKs). As were earlier versions of the embedded tools, device kits are separate from Visual Studio .NET and may be installed and updated independently. Additions to the IDEIn addition to all of the features found natively in Visual Studio .NET, there are the following device-specific features:
Supported LanguagesThe .NET Compact Framework supports two development languages, C# .NET and Visual Basic .NET. While previous versions of Windows CE development tools favored C-based languages—namely eMbedded Visual C++—with the .NET Compact Framework it makes little difference which of the languages you choose, because both are equally powerful and functional. As a late addition to the Visual Studio .NET development environment, J# is not supported by the .NET Compact Framework. You should also be aware that there is another language limitation under the .NET Compact Framework that does not exist under the .NET Framework. Under the .NET Framework you can use mixed-language components within a single project. In comparison, .NET Compact Framework projects are restricted to a single language, either C# .NET or Visual Basic .NET. The workaround to this single-language project limitation imposed by .NET Compact Framework is to create additional projects using the Class template. Add your alternate language code to the template, and then simply add references to these classes in your application project. Online DocumentationThe documentation included with Visual Studio .NET provides information relating to the .NET Compact Framework. You will find both .NET Compact Framework-specific topics, such as "Creating Custom Controls with the .NET Compact Framework", and line item identification of features supported under the .NET Compact Framework. Figure 1 shows an example of the DataTable properties supported under the .NET Compact Framework. Each of the supported properties carries the note "Supported by the .NET Compact Framework". This is an excellent way to find out what features an object supports, and to ascertain quickly the differences between the .NET Framework and the .NET Compact Framework.
Figure 1. Online HelpCreating a .NET Compact Framework ApplicationWhen Visual Studio .NET is launched, it will display the Start Page, as shown in Figure 2. From the Start Page, you can open existing projects and create new projects, including projects that target the .NET Compact Framework.
Figure 2. The Visual Studio .NET Start PageClicking the New Project button causes the New Project dialog box to be displayed, as shown in Figure 3. From this dialog box, you can select a template to create a wide variety of project types, including two that target the .NET Compact Framework. Under both the Visual Basic Projects and Visual C# Projects folders is a Smart Device Application template.
Figure 3. The New Project dialog boxStarting a Visual Basic .NET ProjectTo create a Visual Basic .NET project
Starting a Visual C# .NET ProjectTo create a Visual C# .NET project
The Smart Device Application WizardSelecting the Smart Device Application template will result in the loading of the Smart Device Application Wizard, as showing in Figure 4. This wizard is used to walk you through the process of selecting the project type for your application.
Figure 4. The Smart Device Application WizardThe interface of this wizard is divided into two list boxes. The top list box allows you to select the target platform. It contains two options, Pocket PC or Windows CE. Where Pocket PC targets a specific device platform, the Windows CE template is used to create a more general-purpose application that could run on a variety of devices that are running that operating system. The lower list box displays the project types that are available for the target device (Pocket PC or Windows CE) you selected. Pocket PC Project TypesFour project types target the Pocket PC and Pocket PC 2002 platforms, as shown in Figure 5. These are Windows Application, Class Library, Non-graphical Application and Empty Project. A description of each of these project types is provided in Table 2.
Figure 5. Pocket PC project typesThese project types can be used to create applications that target Pocket PC devices running SH3, MIPS or ARM processors and Pocket PC 2002 devices with ARM or XScale processors. Table 2. Pocket PC project types
Note The Pocket PC device does not come with console support. As a workaround you can load console.dll yourself, which is available with Platform Builder. Windows CE Project TypesAs shown in Figure 6, four project types target the Windows CE platform. These are Windows Application, Class Library, Console Application and Empty Project. A description of each of these project types is provided in Table 3.
Figure 6. Windows CE project typesTable 3. Windows CE project types
Setting Project PropertiesAs with all Visual Studio .NET projects, .NET Compact Framework projects are configured using the Project Property Pages dialog box. Through this dialog box, you can configure namespaces that you want included; what form to use as your startup form; an icon to associate with your application; how your application will be built; where it will be built; how it will be deployed; optimization configurations and a variety of other settings. There are two methods for accessing the Property Pages dialog box:
Figure 7. The Property Pages dialog boxCreating the InterfaceIf you are already an experienced Visual Studio .NET developer, you will require little orientation to begin creating user interfaces for applications that target the .NET Compact Framework. For those who are new to the Visual Studio .NET IDE, new projects based on the Windows Application template will automatically display a default form as shown in Figure 8. In this example, the project type is a Windows Application that will target the Pocket PC. The template for this type of application includes a form that is sized correctly for the Pocket PC platform. A menu control, shown below the form, is included with the form because most Pocket PC applications include menus.
Figure 8. Default Pocket PC formControls that are IncludedThe .NET Compact Framework includes a subset of the controls that can be used to construct a desktop Windows application. For the most part, you will find that these controls offer a subset of equivalent controls found under the .NET Framework. This difference has to do with resource limitations imposed by the target platforms. The controls provided through .NET Compact Framework are shown in Table 4. Table 4. Controls included with the .NET Compact Framework
Note There are also a number of third-party controls available. Refer to the reference section at the end of this document for more details. Building Custom ControlsOne of the coolest features about the .NET Compact Framework is how it enables you to code around limitations. Take controls, for example. All of the controls delivered with the .NET Compact Framework are limited in comparison to their full-Framework counterparts. They are missing properties, methods and events. Through the .NET Compact Framework, you can modify the functionality of the standard controls to fit just your need. You can divide custom controls into three categories: user, inherited and owner-drawn. User controls are the simplest to create, but unfortunately are not supported under the .NET Compact Framework. Inherited controls start with a .NET Compact Framework control. They then add, remove or modify the properties, methods and events of that base control as desired. As complexity of a control goes, inherited controls tend to fall between user and owner-drawn controls. Owner-drawn controls offer the most flexibility in the way of their interface. They also require the greatest amount of work. While the process of creating custom controls for the .NET Compact Framework is outside of the scope of this article, you will find that most of the techniques and approaches used with the .NET Framework carry over to .NET Compact Framework. The following links provide additional details on creating custom controls for use with the .NET Compact Framework:
Constructing a MenuLook at any commercially successful Pocket PC application, and you will find a menu bar. Almost without exception, to build a highly effective Pocket PC application with a fair set of functionality requires the use of a menu bar. The use of menu bars is so common that the default Pocket PC Windows Application template automatically attaches a menu bar to the initial form it creates. With Visual Studio .NET and the .NET Compact Framework, building menus is easy and straightforward. You simply build a menu hierarchy with a graphical tool provided through the Forms Designer. While constructing menus with the design-time tool is the easiest approach, it's not the only approach. Menus can also be constructed with code. While slightly more complicated, there are situations where you will want to create your menus on the fly while your application is running. It is the To activate the Menu Designer
Coding a menu itemIf you are building a menu, you need to respond to the user tapping, or clicking, a menu item. Each menu item has a Click event procedure that executes when the user taps on the item. Listing 1 shows an example of such a procedure. Listing 1. A click event procedure for a menu item '[Visual Basic]
Private Sub mnuEditCut_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuEditCut.Click
MessageBox.Show("cut...")
End Sub//[Visual C#]
private void mnuEditCut_Click(object sender, System.EventArgs e)
{
MessageBox.Show("cut...");
}
Constructing a ToolbarDesktop developers should note that toolbars as they exist in the Pocket PC environment are different from those deployed with a standard desktop application. Most notably, Pocket PC toolbars appear at the bottom of an interface, rather than the top. In addition, they are always limited to a small number of buttons, a restriction enforced by the minimal screen real estate offered on the Pocket PC. Both of these traits can be seen in Figure 12.
Figure 12. An example toolbarToolbars serve two important roles in an application. First, they add some spice. Pocket PC applications in general, because of the limited size, tend to be plain in appearance. Toolbars, and the buttons they contain, can give your application's interface visual 'punch'. Second, toolbars simplify user interaction. Commonly used functions and features can be placed on a toolbar instead of nesting them in a menu. The advantage of this is that accessing a toolbar button requires only a single tap. In comparison, a menu item requires at least two taps, and possibly a third if the item is part of a submenu. This process of constructing a toolbar is divided into three steps:
Coding a toolbarWith toolbars, you are only concerned about a single event, the event that fires when the user taps on a button. That event is the The only issue when working with this event procedure is determining which button was tapped. This can be easily accomplished by referencing the event arguments passed to the procedure. By referencing Listing 2. Handing toolbar button taps '[Visual Basic]
Private Sub tlbMain_ButtonClick(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) _
Handles tlbMain.ButtonClick
Select Case e.Button.ImageIndex
Case 0
MessageBox.Show("print...")
Case 1
MessageBox.Show("task...")
End Select
End Sub//[Visual C#]
private void tlBMain_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (e.Button.ImageIndex)
{
case 0:
MessageBox.Show("print...");
case 1:
MessageBox.Show("task...");
}
}
Adding CodeNow that you have seen the basics of constructing an interface, we are ready to turn our attention to how you add code to your application. As with any applications developed within the Visual Studio .NET IDE, code is added through the Code window. If you are new to the Visual Studio .NET, environment you are in for a treat. The Code window provides a plethora of functionality, everything from statement completion, to auto-listing members, providing parameter information and collapsible regions of code, just to name a few. The easiest way to navigate through your code is by using the two combo boxes located at the top of the window. The combo box at the top left of the Code window allows you to select a class within a module. The combo box at the top right of the window allows you to select a method from within that class. Testing Your ApplicationWith the user interface completed and the code written, it is time to turn our attention to testing your application. Visual Studio .NET offers two methods for testing applications that target the .NET Compact Framework: through an emulator and on a device. With either the emulator or a device, Visual Studio .NET handles deploying both your application and all of the components your application requires, including the .NET Compact Framework and SQL Server CE. All this is handled when you test a .NET Compact Framework application from within Visual Studio .NET 2003. A check of the target platform is made to confirm that the .NET Compact Framework is installed. If Visual Studio .NET determines that the .NET Compact Framework is missing, it will automatically copy and install the .NET Compact Framework before attempting to run your application. This installation process will occur the first time you test to a device or the emulator and if you hard reset either the device or emulator. A similar process is used if your application uses SQL Server CE. Visual Studio .NET will check the target platform to confirm that the SQL Server CE components are installed. If Visual Studio .NET does not find them, it will automatically copy and install the required SQL Server CE components before running your application. After it has been determined that all of the components required by your application are present, your application will be copied to the target platform, placed in the directory you specified in your project configurations and finally launched. Running a TestThere are several ways to run a test of your application:
Testing in the EmulatorThe emulator provides an environment within your desktop PC that mimics the functionality and operation of the device platform you are targeting with your application. The emulator is useful in situations where you do not have a device or when your device is not available. Be forewarned: Testing in the emulator has its shortcomings. First and foremost is that the emulator runs on a desktop PC, which has far more processing resources than the target device. This can give you a false sense of how well your application performs. In addition, input for the emulator is provided through a keyboard and a mouse rather than the stylus the end user will use. If you are not consciously aware of this difference, you can create an application that is easy to use in the emulator and painful to use on the device. Finally, the emulator offers a "close" representation of a device, not an exact match. There are subtle differences in all emulators. Emulator RequirementsThe emulators provided with Visual Studio .NET will not operate unless the development PC on which it is running has a network connection. If your PC does not have a network connection, you can still use the emulator by installing the Microsoft Loopback Network Adapter. This adapter simulates a network connection and effectively fools the emulator into running. Installing a loopback adapter under Windows 2000Under Windows 2000, the process for installing the Microsoft Loopback Network Adapter is as follows:
Configuring a loopback adapter under Windows 2000Like 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 loopback adapter:
Moving Files to the EmulatorEarlier versions of Windows CE / Pocket PC emulators offered two distinct approaches to creating the emulator environment. The first generation of emulators used a closed environment, which was inaccessible from standard Windows-based file management tools found on the development PC. Any files that you needed on the emulator had to either be created within the emulator or copied to the emulator using specialized utilities that were included with the eMbedded Visual Tools. Second-generation emulators provided a more open environment, one that was accessible using common tools, such as File Explorer. The emulator directory structure existed in a subdirectory on the development PC. Copying files to and from the emulator was a simple drag-and-drop operation. The emulator included with Visual Studio .NET returns us to the closed emulator environment. To complicate matters, unlike earlier versions of the eMbedded Visual Tools, Visual Studio .NET does not include an emulator file management tool. This absence requires some creative work-around on your part. There are three common ways to provide files within the emulator environment. One way is to create the files through applications that run on the emulator. I don't believe that this approach requires any additional discussion here. You can use standard .NET programming techniques to create text, XML or database files. The other two approaches, adding files to your project and copying files from a share, require some additional explanation. Adding files to projectThe easiest method to move files to the emulator is to include them as part of your project. One advantage to using this approach is that in the event that you perform a hard reset on the emulator, you simply need to rebuild your project to resume testing. The process for using this approach is:
Copying files from a shareThe second approach offers more flexibility, and requires a minimal amount of additional work. It makes use of the network file sharing functionality built into the Pocket PC operating system, which subsequently is made available through the emulator included with Visual Studio .NET. There are two parts to this approach: setting up a share on your development PC and then accessing that share through the emulator's File Explorer. Setting up a share requires two configurations. First, you must configure you PC to enable sharing. Second, you configure individual folders to share. To enable sharing on a development PC running Windows 2000
At this point, you have configured your development PC to allow file sharing. Next, you need to share a folder where you will place the files you wish to copy to the emulator. To share a folder under Windows 2000
With your development PC configured, you're ready to copy files. First, you'll need to place all of the files destined for the emulator in the shared folder. Then, to move the files to the emulator, perform the following steps:
At this point, you're ready to copy files to and from the share on your development PC and the emulator. Note These same approaches for copying files work equally well when using a device, but there is one known issue. Pocket PC devices by default have the device name "Pocket PC". Unless you change this name, you will not be able to access a share. Testing on a DeviceTesting on a device allows you get a first-hand experience with how your applications perform. With Visual Studio .NET you can test on devices connected to your development PC via USB, serial or Ethernet. Note Use Ethernet to connect your device to your development PC. This is by far the quickest and easiest method for testing and debugging. Deploying to a DeviceYou can select to deploy to a device using any of the following ways:
Debugging Your ApplicationThe debugging environment provided through the Visual Studio .NET IDE is robust. It allows you to pause your application, see its inner workings, modify code, examine values and step through your application in a systematic manner. The core of the debugging functionality can be found on the Debug menu in the Visual Studio .NET IDE. From this menu, you can start and stop a debugging session, set breakpoints, and navigate about your application while in debug mode. Note Breakpoints identify a line of code within your application where you want to pause or interrupt the execution of your application when encountered. Visual Studio .NET enables you to remotely debug applications that are running on a device or in an emulator from the comfort of your development PC. You can use the Command window to enter statements, query and set variables, execute lines of code and other similar tasks. Note For the optimal debugging environment, use Ethernet to connect your device to your PC. Deploying Your ApplicationCreating setups for a .NET Compact Framework application is similar to the approach used for other Windows applications. Application setups are delivered using cabinet files, more commonly referred to as "CAB" files, after their .cab file extension. CAB files serve two purposes: 1) they compress and store files so that they may be easily distributed; 2) they make sure that all of the files and settings required by an application are correctly handled. What is required?Applications built with Visual Studio .NET require that the .NET Compact Framework be resident on the target device. In addition, if the application makes use of SQL Server CE, you'll need to install the SQL Server CE components as well. Your setup routine will need to take all of this into consideration. It may need to include multiple CAB files: one for your application, a second for the .NET Compact Framework and the SQL Server CE CABs. Creating a CAB FileThe easiest way to create a CAB file for your application is to let Visual Studio .NET do all of the work for you. One of the features offered through Visual Studio .NET is a menu item within the IDE for generating CAB files. To build a CAB file for an application
CAB File OutputOutput from this CAB-building process is stored in a directory located under your application's directory. You will find the individual CAB files under the subdirectory \bin\release. An example of this hierarchy is shown in Figure 15.
Figure 15. The location of CAB files generated through Visual Studio .NETIn the example shown in Figure 15, there were several CABs generated, one for each of the target platform processor types. In this figure, you can see the four CABs, one each for the StrongArm, MIPS, SH3 and X86 processor types. This is because the deployment device was a Pocket PC, and these four processor types are supported for that device. At this point, you could copy the appropriate CAB file to your target device, open up File Explorer on the device, tap on your CAB file and your application would be installed. Note Remember, for your application to be able to run, you will need to install the .NET Compact Framework and, if required, SQL Server CE. Creating a Desktop SetupThe installation process becomes slightly more complex if your application setup will be performed from a desktop PC, through a docking cradle to a device. In this situation, you will need two setups, one for the desktop PC and one for the device. The device setup is the CAB file. The desktop setup is an executable that performs two functions. First, it copies your CAB files onto the desktop PC. Second, it starts Application Manager (CeAppMgr.exe). Application Manager then takes over to copy your CAB file to the device and subsequently launches the install. Application Manager handles adding and removing applications from devices as well as deleting application files from the PC that initiated the installation. You use an .INI file to provide installation instructions to Application Manager. Desktop setups can be created with any application that allows you to copy your CAB files to a PC and then launch Application Manager. Two companies, InstallShield and Wise, provide commercial-grade installation development packages that provide this functionality. Spb Software House offers a free setup product called EZSetup. While this application is not as robust as the products from InstallShield and Wise, it functions quite well for most setups. Note If you are going to write your own desktop setup you will need to find where Application Manager is located on the installation PC. The full name and path of Application Manager is stored in the registry value of HKLM\software\Microsoft\Windows\CurrentVersion\App Paths\CEAppMgr.exe. SummaryThe .NET Compact Framework presents developers with a powerful tool for creating robust mobile applications. It enables you to leverage you existing .NET skills in the construction of applications that target Pocket PC and Windows CE .NET devices. The .NET Compact Framework is a subset of the .NET Framework. While similar in appearance and functionality to the .NET Framework, learning how to program under the .NET Compact Framework will take time and effort. You will need to master the limitations imposed by Windows CE devices and the demands associated with creating mobile applications. Where to go for Additional InformationArticlesGetting started
Creating custom controls
Newsgroups
Web SitesDeveloper programs
Training and jump-starting programslarryroof.com offers training and project consulting in designing and developing mobile applications. Services offered include 5-day training courses in the .NET Compact Framework and SQL Server CE, customized training programs and combinations of training and project consulting to aid you in quickly implementing effective mobile solutions. Information sites
Third-party controls and components
Links
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||