47
Embedded Applications: Getting Started with Smart Device Extensions for Visual Studio .NET

Migrating from eVB to VB - Freie Universität · Web viewCode management can take the form of memory management, thread management, security management, code verification and compilation,

Embed Size (px)

Citation preview

Embedded Applications: Getting Started with Smart Device Extensions for Visual Studio .NET

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.

This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE INFORMATION IN THIS DOCUMENT.

Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. © 2001 Microsoft Corporation. All rights reserved.

Microsoft, ActiveSync, ActiveX, Visual Basic, Visual C++, Visual C#, Visual Studio and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

Page 2

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Table of Contents

INTRODUCTION 5What Is Included with Smart Device Extensions 5Why Not eMbedded Visual Basic 4.0? 6

THE .NET COMPACT FRAMEWORK 6What Is in the .NET Compact Framework? 6

Features of the Common Language Runtime 7.NET Compact Framework Class Library 7

Form-Related Classes 8Data and XML Classes 8Web Services 8Visual Basic Support 8GDI Support 9Base Classes 9

USING THE DEVELOPMENT ENVIRONMENT 9Creating a New Project 10

Constructing a User Interface 12The New Toolbox 13Controls Provided with Smart Device Extensions 14Adding Controls to Your form 15Managing Your Project 16Project Items 16Configuring Properties 18Adding Code 19The Code Behind a Visual Basic .NET Form 20Configuring Your Project 22Building Your Application 23Configuration Manager Dialog Box 24

Testing Your Application 24The Smart Device Extensions Emulator 25

Working with Emulator Images 25Saving and Restoring Images 25Image Functionality 26Localization Issues 26Automated Testing Environment 26Obtaining Additional Images 26Summary of the New Emulator 26

Testing on a Device 26Remote Tools Included with SDE 26

Page 3

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

DIFFERENCES BETWEEN EMBEDDED VISUAL BASIC AND VISUAL BASIC .NET 27

Variant Is No Longer Supported 27Integer Data Types 27Declaring Values While Dimensioning a Variable 27Fixed-Length Strings Are Not Supported 27Use Zero Bound Arrays 27Default Properties 27Subs and Functions Require Parentheses 28Optional Arguments Are Not Allowed 28New Assignment Operators 28New Error Handling 28Support for APIs 29Accessing Data 29

What Are Datasets? 31Visual Basic .NET Compact and XML 31

XML Functionality Included Under the .NET Compact Framework 31Local Data Storage Using XML 32

Working with Files Under SDE 32Working with XML Web Services 33

GETTING STARTED WITH SMART DEVICE EXTENSIONS 33

WHERE TO GO FROM HERE 34

APPENDIX A – FUNCTIONALITY NOT INCLUDED IN THE .NET COMPACT FRAMEWORK 35

Features Not Included in the .NET Compact Framework 35General Functionality Not Included in the .NET Compact Framework 35XML Functionality Not Included in the .NET Compact Framework 35

Page 4

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

IntroductionTo the developer experienced with Microsoft eMbedded Visual Basic®, the prospect of gaining access to Visual Basic .NET capabilities on a mobile platform may seem too good to be true. With the release of Smart Device Extensions (SDE) for Visual Studio® .NET, Microsoft has done just that. SDE provides a compact version of theMicrosoft .NET Framework, allowing you to build applications in Visual Basic .NET without the previous limitations that thwarted and restricted mobile developers. With SDE, developers have a tool based on the Visual Basic language that can be used to create robust applications, with all of the power and flexibility that previously was reserved for applications created with Microsoft eMbedded Visual C++®.

For those who have yet to work with Visual Basic .NET, the scope of the changes between this most recent version of Visual Basic and the previous versions are too great to cover in this document. Instead, you will be given a general overview of the .NET Compact Framework, and you will learn about the new integrated development environment (IDE) and language differences, as well as the key features provided by SDE for Visual Studio .NET.

What Is Included with Smart Device ExtensionsSDE for Visual Studio .NET offers developers a scaled-down version of the .NET Framework, called the .NET Compact Framework. SDE is a Visual Studio Integration Package, or VSIP, which plugs into Visual Studio .NET. Unlike eMbedded Visual Basic, SDE cannot operate without Visual Studio .NET installed. Other than that, no other products are required for developing and deploying applications for the Pocket PC or the Pocket PC 2002 built using SDE.

Included as part of the SDE is a set of prebuilt device profiles. An embedded device profile contains information necessary to build specific types of applications that target specific devices. For example, one profile enables you to create applications for a Pocket PC, Pocket PC 2002, or Microsoft Windows® CE .NET device by using WinForms, Microsoft ADO.NET, and the ability to consume XML Web services. Other profiles could be provided that would allow you to create applications that would target cell phones or third-party personal digital assistants (PDAs).

Profiles may target specific devices, such as the Pocket PC. Less specific profiles may target the Windows CE platforms in general. Generic profiles may target any platform to which the .NET Compact Framework has been ported.

In addition, the SDE will include device kits (formerly known as SDKs). As with eMbedded Visual Basic, device kits are separate from SDE and may be installed and updated independently.

Page 5

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Why Not Offer eMbedded Visual Basic 4.0?You may be wondering why such a drastic change was made to the Visual Basic-based development tool for Windows CE. The answer is fairly simple. The current eMbedded Visual Basic 3.0 product is not suited for advanced development. Based on Visual Basic Scripting Edition (VBScript), its engine works well enough for simple applications, but it is cumbersome and lacks some of the key features required for advanced development. Developers using eMbedded Visual Basic end up spending a significant amount of their time learning tricks to work around its inherent limitations. As the popularity of mobile devices has increased, device developers have been requesting a rich, strongly typed, object-oriented Visual Basic development tool, similar to what is now offered in Visual Basic .NET. They want to be able to build wireless solutions that leverage the Internet and XML Web services. SDE for Visual Studio .NET delivers on these requests. Microsoft has ported the .NET Framework to Windows CE .NET, which enables applications written in Microsoft Visual C#™ .NET and Visual Basic .NET to target the device platform.

The .NET Compact FrameworkAny discussion of SDE would be incomplete without including an overview of the fundamentals of the .NET Compact Framework. In developing applications using .NET-based technologies—whether you are targeting the .NET Framework or the .NET Compact Framework—you can take advantage of the functionality provided by the .NET Framework classes, and you can use the same programming model. In the case of applications developed with SDE, you target the .NET Compact Framework.

What Is in the .NET Compact Framework?The .NET Compact Framework simplifies application development on smart devices by providing two main components: the common language runtime and the .NET Compact Framework class library.

The common language runtime is the foundation of the .NET Compact Framework. It is responsible for managing code at execution time and providing core services, such as memory management and thread management, while enforcing code safety and accuracy. Code that targets the runtime—for example, code written in Visual Basic .NET and Visual C# .NET—is known as managed code; code that does not target the runtime—for example, code written in eMbeddded Visual C++, is known as unmanaged or native code. In a way, you can think of the common language runtime as the eMbedded Visual Basic runtime on performance-enhancing drugs.

NOTE Managed code, such as that generated by Visual Basic .NET (targeting either the .NET Framework or the .NET Compact Framework), is handled by the common language runtime.

The .NET Compact Framework class library is a collection of reusable classes that you can use to develop applications quickly and easily. This framework is designed so that it can be ported to other platforms, whether they are created by Microsoft or other vendors. What does this mean to you? The coding techniques and the applications you create today

Page 6

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

to run on a Pocket PC, for example, could just as easily 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. For that matter, the coding skills you have already developed with Visual Studio .NET can also be used with any of the platforms that support the .NET Compact Framework.

Features of the 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.

Even though your mobile applications are written in Visual Basic .NET, and as such are managed code, they are still able to incorporate functions in dynamic-link libraries (DLLs). In fact, Visual Basic .NET provides extensive support for data types and structures, so you are able to use the Windows CE APIs in ways you could only dream of with eMbedded Visual Basic.

NOTE Unlike eMbedded Visual Basic, Visual Basic .NET provides the data types and includes support for structures that allow you to easily incorporate functions from the Windows CE APIs into your applications. While the need for these functions is far less in Visual Basic .NET in comparison to eMbedded Visual Basic, that capability allows you to create mobile applications that match the functionality found in applications written in eMbeddded Visual C++.

The common language runtime is designed to enhance performance. It makes use of Just-in-Time (JIT) compiling, which enables managed code to run in the native machine language of the target platform. This feature allows you to create applications that can target a variety of platforms without recompiling or generating separate executables for each specific platform on which your application will run.

The .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 Visual Basic .NET applications derive functionality from these libraries.

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 string management, data collection, database connectivity, and file access.

NOTE: Unlike eMbedded Visual Basic, which had many differences in functionality from Visual Basic, Smart Device Extensions implements a true subset of the .NET Framework. The classes included in the .NET Compact Framework provide an identical interface to their .NET Framework equivalent, with the exception of functionality that is not supported because of size constraints, performance issues, or limitations in the target operating system. Class behaviors, properties, methods, and enumeration values will be the same under both

Page 7

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

versions of the .NET Framework, so you can use your Visual Basic .NET coding techniques to create both desktop and device applications.

The following section details functionality available through Smart Device Extensions.

Form-related ClassesThe .NET Compact Framework implements a subset of the System.Windows.Forms and System.Drawing classes. These classes can be used to construct rich, Windows CE-based user interfaces for device applications. Much of the interaction with these classes is managed for you by the Windows Forms Designer in Visual Studio .NET.

The implementation of Windows Forms under the .NET Compact Framework includes support for forms, most controls found in the .NET Framework, the ability to host third-party controls, as well as support for bitmaps and menus.

Data and XML ClassesThe .NET Compact Framework includes a set of classes that allow you to easily incorporate data from either a relational or nonrelational data source. Working with Extensible Markup Language (XML) content is straightforward in device applications created using Visual Basic .NET. The implementation of both data and XML classes under the .NET Compact Framework is a subset of those found in the .NET Framework. Additional details on both the data and the XML classes are included below.

XML Web ServicesThe .NET Framework provides deep support for XML Web services. In the .NET Compact Framework, you have a subset of the capabilities and functionality offered in the .NET Framework. Most significantly, you can use Visual Studio .NET and SDE to create applications that allow you to easily consume XML Web services. More on this subject is included below.

NOTE: When using Visual Basic .NET to target the .NET Framework, you can create both XML Web service clients and servers—but the .NET Compact Framework is only a consumer of XML Web services.

Visual Basic SupportVisual Basic .NET makes liberal use of helper functions that are located in a Visual Basic Helper library. The version of the Visual Basic Helper library included with the NET Compact Framework offers a subset of these functions. The functions included in the Visual Basic Helper library are considered by Visual Basic developers to be a core part of the language, and they include many of the keywords with which developers are experienced.

The inclusion of the Visual Basic Helper library means that eMbedded Visual Basic developers will be able use many of their favorite Visual Basic statements and functions when working in Visual Basic .NET.

Page 8

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

NOTE: The Visual Basic Helper library included with the .NET Compact Framework is a subset of the library included with Visual Basic .NET. Refer to the help documentation included with Smart Device Extensions to verify that particular functions are supported.

Graphics Device Interface SupportThe .NET Compact Framework provides support for the basic graphics device interface (GDI) drawing elements, including bitmaps, brushes, fonts, icons, and pens. The addition of this functionality offers a great advantage to Visual Basic .NET over eMbedded Visual Basic, where drawing capabilities have been limited.

Base ClassesThe .NET Compact Framework provides a robust set of base classes that expose a wide range of functionality for use by developers working in Visual Basic .NET. This underlying infrastructure enables you to write rich .NET-based applications that incorporate multithreading, access network resources, and work with files.

Using The Integrated Development EnvironmentSmart Device Extensions for Visual Studio .NET is a Visual Studio Integration Package, or VSIP, which plugs into Visual Studio .NET. As a VSIP, SDE makes use of the Visual Studio .NET integrated development environment (IDE). This IDE provides a development experience that is unmatched in previous versions of the Windows CE development tools.

This section shows the key components of the Visual Studio .NET IDE as they are used in creating a Windows CE-based application.

Page 9

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Creating a New ProjectWhen Visual Studio .NET is first run, the Start Page is displayed, as shown in Figure 1. The Start Page is used to open existing projects and to create new projects, including projects that target the .NET Compact Framework.

Figure 1. The Visual Studio .NET Start page

Page 10

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

When you click the New Project button, the New Project dialog box is displayed, as shown in Figure 2. From this dialog box, you can select a template to use for your application. SDE installs a set of templates in both the Visual Basic and Visual C# project folders.

The Visual Basic Projects folder includes templates for Pocket PC devices as well as for devices that use Windows CE .NET. These templates provide the basic project configuration required for creating applications. A project template for Pocket PC is highlighted in Figure 2.

Figure 2 shows two additional templates: Device class library templates are used to construct class libraries for their respective devices, and control library templates are used to create controls.

NOTE: The addition of control and class libraries to Visual Basic .NET is a significant enhancement over eMbedded Visual Basic.

Figure 2. The New Project dialog box showing three Pocket PC-related templates

Page 11

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

The Windows CE Application template included with SDE, as shown in Figure 3, enables a developer to build a .NET Compact Framework project that targets any device that runs Windows CE and supports the .NET Compact Framework.

Figure 3. The New Project dialog box showing the Device Project wizard

The Pocket PC project templates, as with all device templates, create the initial files, references, code framework, property settings, and tasks as appropriate for the selected project type. Device templates take into account the target platform, which in turn affects which .NET Compact Framework libraries are available for use by the developer.

Constructing a User InterfaceIf you have experience working with Visual Studio .NET, you will require little orientation to begin working with the SDE. For eMbedded Visual Basic developers just starting with .NET, the following section leads you through the key features of the Visual Studio .NET IDE.

Page 12

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

When you create a new project, the Start Page will be replaced by a blank form as shown in Figure 4.

Figure 4. The Windows Forms designer

At first glance, this part of the Visual Studio .NET IDE appears similar to the forms designer in eMbedded Visual Basic. On closer inspection, you will notice a set of tabs along the top of this window. In the figure above, three tabs are shown: Start Page, Form1.vb, and Form1.vb [Design].

In addition to the Start Page, these other two tabs correlate to the form interface and form code module in eMbedded Visual Basic. The Visual Studio .NET IDE allows you to easily switch between user interface design and code windows by using these tabs.

The New ToolboxThe Toolbox in the Visual Studio .NET IDE is located in the same general location as it was in eMbedded Visual Basic, but initially it is hidden. The Visual Studio .NET IDE supports panels that automatically hide themselves when not in use. This feature allows more available screen space for designing forms and writing code.

Page 13

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

In its hidden state, the Toolbox appears as shown in Figure 5A, aligned along the left side of the IDE. Placing your cursor over the Toolbox tab will cause it to be displayed as shown in Figure 5B.

Figure 5A Figure 5B. The Visual Studio .NET toolbox

Controls Provided by SDEWhile eMbedded Visual Basic provided a limited set of controls, SDE includes a far more comprehensive set, many of which support data binding. A list of the controls is shown in Table 1 below.

Button CheckBox ColorDialog ComboBox ContextMenuDateTimePicker DomainUpDown ErrorProvider GroupBox HScrollBarImageList Label LinkLabel ListBox ListViewMainMenu MonthCalendar NumericUpDown OpenFileDialog PanelPictureBox ProgressBar RadioButton SaveFileDialog StatusBarTabControl TextBox Timer ToolBar ToolTipTrackBar TreeView VScrollBar

Table 1. The controls included with SDE

Page 14

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Adding Controls to Your FormWorking with the Visual Studio .NET Toolbox is identical to the eMbedded Visual Basic approach. Simply select the control in the Toolbox, and then draw the control on your form. In Figure 6, a button has been added to a form. Visual Studio .NET offers a complete set of user interface configuration tools under the Format menu, so the developer can align, size, space, center, and lock the control in position.

Figure 6. Adding a button to a form

Page 15

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Managing Your ProjectYou manage your .NET Compact Framework projects using the Solutions Explorer window. Similar in functionality to the Project Explorer window in eMbedded Visual Basic, the Solutions Explorer window, shown in Figure 7, is used to access and configure your project and its components.

Figure 7. The Visual Studio .NET Solution Explorer window

Project ItemsWhile eMbedded Visual Basic was limited in the scope of supported project items, with only form and standard modules, SDE provides a broad set of project items from which to choose. Table 2 details the supported items along with their file extensions.

Project Item File Extension

Description

Assembly Info File .vb A file used to store assembly information, such as versioning and assembly name.

Assembly Resource File

.resx A file containing localization information for a project when the Localized property is set to true.

Bitmap .bmp A blank bitmap image file, which can be used to create simple images.

Class .vb A code file that initially contains a single empty class declaration.

Code File .vb An empty Visual Basic or Visual C# code file.

Component Class .vb A class (a business object) for which a visual designer exists.

Cursor File .vb An image file for creating custom cursors.

Page 16

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Custom Control .vb A Windows-based control that is not visually designed (it does not have a graphical design surface). You must create the control by writing code.

Data Form .vb A data form that assists in creating data connections.

Data Set .xsd An XSD schema that generates classes you can use to access the dataset programmatically.

Dynamic Discovery Document

.vsdisco Sometimes called a disco file, this provides a means to enumerate all Web services and all schemas in a Web project.

Icon File .vb An image file for creating a custom icon.

Inherited Form .vb A Windows form that you derive from another form by using visual inheritance. When you inherit from another form, you receive this form as your initial form. You can then visually add to it or change its contents.

Inherited User Control

.vb A User Control that is derived from another existing user control.

Module (Visual Basic only)

.vb A code file that initially contains a single file for storing functions.

Static Discovery File

.disco A file used to publish information about an XML Web service.

Text File .txt An empty text file.

User Control .vb A control (a visual element) that you can place on a Windows form. It has a visual designer.

Windows Form .vb A basic Windows form that you use for local applications. It has a graphical design surface.

XML File .xml An XML document file.

XML Schema .xsd An XSD schema file without the generated classes.

Table 2. Supported file types provided br SDE

Page 17

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Configuring PropertiesThe Visual Studio .NET Properties window enables you to configure the properties of forms and controls. The Properties window, as shown in Figure 8, offers both a categorized and alphabetic view. The categorized view can be collapsed or expanded to facilitate working with particular sets of properties.

Figure 8. The Visual Studio .NET Properties window

NOTE: In Visual Basic .NET, some property names of controls have been altered from those used in eMbedded Visual Basic. For example, the Visual Basic .NET button offers a Text property in place of the expected Caption property.

Page 18

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Adding CodeThe Visual Studio .NET code window, as shown in Figure 9, is similar to the eMbedded Visual Basic version. The main editing area enables you to collapse and expand sections of code. The combo box at the top left of this window allows you to select a class, where eMbedded Visual Basic allowed you to select an object. The combo box at the top right of the code window allows you to select a method, whereas eMbedded Visual Basic allowed you to select a procedure. The Visual Studio .NET code window features Microsoft IntelliSense® statement completion, including automatically listing members and providing parameter information.

Figure 9. The Visual Studio .NET code window demonstrating IntelliSense

NOTE: Visual Basic .NET supports overloading methods. For the typical eMbedded Visual Basic developer, overloading is a new concept. Simply stated, overloading allows you to declare a method multiple times, each time with a different parameter list. In the figure above, you can see the addition of a navigational feature at the left side of the method description window. This navigational tool allows you to select the method description that best suits your development needs. On a related note, Visual Basic .NET requires that you provide values for all parameters defined for a method. Visual Basic .NET does not support optional arguments.

Page 19

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

The Code Behind a Visual Basic .NET FormWhen you create a form using Visual Basic .NET, you are, in fact, creating the code used to define your form’s interface. This is unlike eMbedded Visual Basic, in which form definitions were described separately from the form’s code.

The Windows Form Designer automatically generates this code and adds it to the form’s code module as shown in Figure 10. This code is normally hidden from the developer’s view in what is referred to as a region. The region carries a label titled: Windows Form Designer generated code.

NOTE: This section of your form is created and maintained by the Windows Form Designer component of Visual Studio .NET. You should not manually modify this section of code as it may produce unpredictable results.

Figure 10. Code file with generated code hidden

Page 20

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Regions can be expanded and collapsed by clicking on the plus (+) and minus (-) symbols at the far left of the code window. Expanding the code generated by the Windows Form Designer reveals the code used to define the form’s interface as shown in Figure 11.

Figure 11. Code file with generated code exposed, note the form and control definitions

Page 21

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Configuring Your ProjectProject properties are configured through the Property Pages dialog box. This dialog box can be accessed by selecting Properties under the Project menu, or by right-clicking your project in the Solution Explorer and then selecting Properties from the pop-up menu as shown in Figure 12.

Figure 12. Accessing project properties

Page 22

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

The Property Pages dialog box, shown in Figure 13, allows you to configure all facets of your project, including device deployment details such as the platform, device type, and the target output folder.

Figure 13. Configuring project properties

Building Your ApplicationTo build an application, select Build from under the Build menu. If it is not already displayed, the Output Window will appear as shown in Figure 14.

Page 23

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Figure 14. The Visual Studio .NET Output window displaying the results of a project build

The Output window is used to display deployment messages, exception handling, and status notifications. Deployment messages include device information, source and destination folders, file information, and memory usage. Exception-handling information includes connection time out, insufficient memory, path not found, access denied, sharing violations, cancelled deployments, and other unexpected errors. Status information includes successes, failures, and items that are skipped. You can reference the Output window to aid in the resolution of compilation and deployment issues.

Configuration Manager Dialog BoxThe Configuration Manager dialog box, shown in Figure 15, allows the developer to specify whether to build or deploy a project. To access this dialog box, select Configuration Manager from the Build menu. These configuration settings are referenced when a developer selects to build or deploy an application.

Figure 15. The Visual Studio .NET Configuration Manager dialog box

Testing Your ApplicationLike eMbedded Visual Basic, Smart Device Extensions allow you to test your application in either an emulator or on a device. Similar to the eMbedded Visual Basic IDE, the SDE enhancements to the Visual Studio .NET IDE provide a menu bar interface, as shown in Figure 16, which allows you to select the target for testing.

Page 24

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Figure 16. Selecting a deployment target

The SDE EmulatorSDE improves emulation testing for devices. Previous emulators included with the H/PC, P/PC, H/PC Pro and Pocket PC system development kits were simply Windows-based applications simulating a device environment. The emulator included with SDE runs a binary image of the device’s operating system. For all practical purposes, it is a device running inside of Windows. Accordingly, the emulator will act and operate in the way you would expect your device to function, providing a true representation of the actual device. This type of emulation is referred to as true emulation.

NOTE: The capabilities of the SDE emulator enable application developers to start programming before they have access to the device hardware.

This new emulator runs device operating systems within the computer operating system. The SDE emulator can be used with either Microsoft Windows 2000 or Microsoft Windows XP Professional. This emulator is a separate and complete instance of a virtual machine. Any operating system calls that are made by an application from within the emulator are not patched through to the host operating system.

Working with Emulator ImagesNot only does the emulator, included with SDE, provide a far better representation of the actual device, it also allows the developer to modify, save, and restore custom configurations of operating system images.

Saving and Restoring ImagesOperating system images can be customized by including additional software, files, and registry settings. These customized images can be saved and restored for use with the emulator to meet your development needs.

You can access and configure operating system images running in the emulator by using Microsoft ActiveSync® technology. When you close the emulator, you are asked whether you would like to save or discard changes made to an image.

You can return an image to its original state by using the reset command within the emulator. If it is a default image, it will revert to its shipped state. If it is a developer-saved image, it will revert to the image as it appeared the last time it was saved by the developer.

To use a previously saved image, you simply need to select the desired image from the target device drop down menu within the Visual Studio .NET IDE.

NOTE: Support for saving and restoring images is not included in the beta for Smart Device Extensions.

Page 25

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Image FunctionalityImages running in the emulator act like the actual device. Applications running in the emulator can access the network, consume XML Web services, install software, and perform any other action, just as they would on a device.

Localization IssuesThe emulator enables developers to test applications for localization issues more easily. By obtaining an additional image for each localized version of the target operating system, developers can determine how their applications react without needing to acquire multiple devices.

Automated Testing EnvironmentOne of the benefits of SDE integration within Visual Studio .NET is that SDE can make use of its native functionality—for example, the Visual Studio .NET scripting capabilities. SDE developers can leverage these scripting capabilities in conjunction with the new emulator to automate testing plans and exercise their applications.

Obtaining Additional ImagesImages not included with SDE will be delivered with device kits (formerly known as SDKs). The flexibility offered by this new emulator will allow it to support future versions of Windows CE as they become available.

Summary of the New EmulatorUnlike eMbedded Visual Basic, the emulator included with SDE offers a high-fidelity environment for testing. The features and enhanced functionality of the SDE emulator offer a suitable environment for developers to test and debug their applications.

NOTE: While the new emulator that is included with SDE provides a robust development environment, it should not be used as your sole means of testing. Final testing should always be performed on the target device.

Testing on a DeviceAs with previous versions of the Windows CE development tools, SDE allows you to test your applications on a target device. SDE copies your application and required supporting components to your device, launches your application, and enables you to debug your logic using the SDE IDE.

Remote Tools Included with SDESDE includes a set of remote tools that enable developers to monitor, alter, and control applications running on a connected device. Access to these tools is provided through the Tools menu within the Visual Studio .NET IDE.

Page 26

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Differences Between eMbedded Visual Basic and Visual Basic .NET When migrating from eMbedded Visual Basic to Visual Basic .NET, developers will need to adjust to the differences in the Visual Basic languages as they are implemented in each of these tools. This section highlights some of the key differences between these two versions of the Visual Basic language.

Variant Is No Longer SupportedThe variant data type, the only data type supported in eMbedded Visual Basic, is not available under Visual Basic .NET. In its place, Visual Basic .NET offers a wide variety of data types to meet your programming needs.

Integer Data TypesThere are three integer data types:

16-bit, which are called Short 32-bit, which are called Integer 64-bit, which are called Long.

Declaring Values While Dimensioning a VariableVisual Basic .NET allows you to declare the value of a variable at the time you are dimensioning the variable. For example:

Dim intFactor As Integer = 5

Fixed-Length Strings Are Not SupportedIn Visual Basic .NET, fixed-length strings are not supported. For example, the following eMbedded Visual Basic statement would result in a compilation error under Visual Basic .NET.

Dim strDemo As String*50

Use Zero-Bound ArrayseMbedded Visual Basic allowed you to specify the lower and upper bounds for an array. In Visual Basic .NET, you must use zero for the lower bound.

Default PropertiesWith eMbedded Visual Basic, you could use default properties. When you referenced an object without specifying a property, it would be resolved to the default property for the specific object. For example, the following lines of code operate identically under eMbedded Visual Basic:

Text1 = "something"Text1.Text = "something"

Page 27

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Visual Basic .NET does not support default properties. In all instances, you must specify the desired property.

Subroutines and Functions Require ParenthesesUnder Visual Basic .NET, all calls to subroutines or functions require the use of parentheses. For example, the following eMbedded Visual Basic code:

MsgBox "test..."

will need to be written in Visual Basic .NET as:

MsgBox ("test...")

Optional Arguments Are Not AllowedVisual Basic .NET does not support optional arguments. Any calls to methods or procedures must include values for each argument that is defined.

New Assignment OperatorsVisual Basic .NET supports a new set of assignment operators that are borrowed from the C language. These new operators include:

Type of Operator eMbedded Visual Basic Syntax Visual Basic .NET SyntaxAddition intValue = intValue + 1 intValue += 1Subtraction intValue = intValue - 1 intValue -= 1Multiplication intValue = intValue * 5 intValue *= 5Division dblValue = dblValue / 5 dblValue /= 5String concatenation strValue = strValue & "demo" strValue &= "demo"

NOTE: Visual Basic .NET supports these new operators in addition to the operators available in eMbedded Visual Basic.

New Error HandlingeMbedded Visual Basic lacked adequate error handling. Since eMbedded Visual Basic was built using the VBScript language, it supported only On Error Resume Next. Developers who have worked with this method of error handling are well aware that it often leads to more problems than it solves.

Page 28

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Visual Basic .NET offers a far more robust approach to error handling, if implemented with Try-Catch-Finally structure. An example of this structure is shown in the code sample below.

Try

' Your normal application code goes here.

Catch

' This code gets executed if an error occurs.

Finally

' This code would get executed every time. Typically it is used' as a clean-up area for the error handler.

End Try

Support for APIsThe .NET Compact Framework supports calling functions stored in dynamic-link libraries (DLLs) written in eMbeddded Visual C++, Visual C#, and Visual Basic .NET. Like eMbedded Visual Basic, Visual Basic .NET uses the Declare statement to define these functions. With its support of structures, Visual Basic .NET can call the Windows CE APIs in a far more robust fashion than was allowed with eMbedded Visual Basic.

Visual Basic .NET support for calling DLLs is limited by the following restrictions:

o The number of arguments passed to a DLL function is limited to 12 in total.o American National Standards Institute (ANSI) strings will not be supported. Since

Windows CE is UNICODE based, only UNICODE strings may be used.o Simple types will be supported, but not nested types.

Accessing DataVisual Basic .NET allows developers to interact with device-based databases, such as Microsoft SQL Server™ CE, using the System.Data class. This class includes support for disconnected datasets, which allows developers to work easily with both relational and nonrelational data using the same model that is used with the .NET Framework. Data is passed as XML, allowing rich, open standards-based communication and interoperability.

The Data Connector object exposes managed APIs that can be used to access the local database. Each connector is database-specific—that is, the data connector for SQL Server CE is the SQL Server CE Data Connector.

NOTE: Presently, there are no plans to provide a Data Connector for Pocket Access or the native Windows CE database structure.

In addition to providing local support to SQL Server CE databases, SDE includes a SQL Data Adapter that will provide access to remote SQL Server databases.

Page 29

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

NOTE: Support for SQL Server CE is not included in the beta version of SDE. It will be provided in the final version of SDE.

There is no support for ADOCE in Visual Basic .NET, nor will there be any support for ADOCE on Windows CE .NET. In its place, you can use ADO.NET to access datasets.

NOTE: ADOCE will still be available for use with native, or unmanaged, development tools such as eMbeddded Visual C++ and eMbedded Visual Basic.

From your Visual Basic .NET application, you can access data through the System.Data classes of the .NET Compact Framework. An example of this is shown in the code fragment below.

To begin working with these classes, they must be incorporated into your project.

' These lines must be added to your project declarations: Imports System.Data Imports System.Data.ADO

Instances of the ADO Connection, Command, and Data Reader objects are created. These instances are, in turn, used to connect to and retrieve data from a local SQL Server CE database.

' Declare the ADO object variables. Dim strConnectionInfo As String = _ "Provider=Microsoft.SQLServer.OLEDB.CE.1.0; Data Source=Northwind.sdf" Dim demoConnection As New ADOConnection(strConnectionInfo) Dim demoCommand As New ADOCommand("SELECT * FROM Employees", demoConnection) Dim demoReader As ADODataReader

' Open the database and retrieve the data. Try demoConnection.Open() demoCommand.Execute(demoReader)

' Did an error occur? Catch demoException As Exception MessageBox(demoException.ToString())

' Clean-up before exiting. Finally

' Close the connection if it is open. If (demoConnection.State = Data.DBObjectState.Open) Then demoConnection.Close End If

' Dispose of the Data Reader. If Not demoReader Is Nothing Then demoReader = Nothing End If

End Try

Page 30

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

What Are Datasets?

Developers experienced with ADO are accustomed to working with recordsets. The ADO.NET equivalent to a recordsets is the dataset. A dataset is a disconnected cache that developers can use within their applications. It offers a relational view of the database query stored in XML format. Through datasets, developers can access table, row, and column data. Since datasets are disconnected, they inherently support a scalable model, since the client application does not maintain a database connection for the entire time that the application runs. The SQL Data Connector accesses the database to populate a dataset. The dataset can then be used programmatically or bound to controls, such as text boxes, list boxes, and grids.

NOTE: Recordsets are not included in ADO.NET. Datasets offer a far more flexible approach to working with data sources.

Visual Basic.NET support for datasets and for binding datasets to controls will allow developers to quickly build data-enabled applications. This is a great improvement over eMbedded Visual Basic, in which developers were solely responsible for displaying and managing data.

NOTE: The data grid control is not included in the beta version of SDE. It will be included in the final release of SDE.

Visual Basic .NET and XMLXML is the universal format for data on the Internet. XML allows developers to easily describe and deliver rich, structured data between applications, varied data sources, and different operating systems in a standard, consistent way.

While eMbedded Visual Basic offered low-level support for XML, the .NET Compact Framework provides Visual Basic .NET with a set of tools that make it simple and straightforward to work with XML structures.

XML Functionality Included Under the .NET Compact FrameworkAs with other components of the .NET Compact Framework, the XML-related classes offer a subset of the functionality found in the .NET Framework. The support for XML in the .NET Compact Framework:

o Adheres to the SOAP standards.o Allows developers to create applications that consume dataset from and post

datasets to XML Web services.o Enables developers to read an XML document, manipulate the document, post the

document to a server and maintain the document on the device.

The .NET Compact Framework provides support for the following XML functionality:

Page 31

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

XML Reader. Provides a forward-only, read-only stream of parsed XML tokens.

XML Writer. Provides a forward-only, write-only method for generating well-formed XML documents.

XML Document. Provides access to the XML Document Object Model (DOM).

Local Data Storage Using XMLThe XML support provided by the .NET Compact Framework, and accessible from Visual Studio .NET, allows developers to keep a persistent XML stream in a serialized manner to a local text file. This provides developers with an alternative to relational databases and standard files as a method of storing data.

Developers can use this technique to store configuration information, as well as for offline caching of small, simple data volumes. This method provides a simple yet effective alternative for situations in which a full-functioned relational database is not required.

The following code fragment demonstrates persisting and then retrieving an XML stream from a text file.

Dim demoDataSet As DataSet

Me.demoDataSet = New DataSet() Me.demoDataSet.WriteXml("demo.xml") Me.demoDataSet.ReadXml("demo.xml")

Working with Files Under SDE

With eMbedded Visual Basic, file access and directory information was provided by the File System and File Microsoft ActiveX® controls. In SDE, similar functionality is provided by the .NET Compact Framework System.IO namespace.

The following code fragment demonstrates opening a text file, writing a line of text to the file, and then closing the file in Visual Basic .NET.

Sub DemoWriteFile() Dim demoStreamWriter As System.IO.StreamWriter demoStreamWriter = New System.IO.StreamWriter("\demo.txt") demoStreamWriter.WriteLine("This is a test.") demoStreamWriter.Close()End Sub

NOTE: The file capabilities provided under the Microsoft.VisualBasic namespace are not supported by the .NET Compact Framework. Methods such as FileOpen, FileAttr, and FileCopy, along with many others, are not included.

Page 32

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Working with XML Web ServicesOne of the most powerful new features of Visual Basic .NET is the ability to create applications that access, or consume, an XML Web service. XMLWeb services, running on standard Internet Web servers, expose methods that can be called from your Visual Basic .NET-based applications. Developing an XML Web service client with Visual Basic .NET is simple. It involves adding a reference to the XML Web service, creating an instance of the XML Web service, and then calling the methods provided by the XML Web service.

NOTE: The implementation of an XML Web service under the beta of the SDE is limited and is missing key .NET Framework classes. As such, some additional work needs to be done to construct XML Web service clients. Refer to the Stock Quote and Inventory samples included with the beta for examples of how to work around this issue.

Getting Started with Smart Device ExtensionFor the eMbedded Visual Basic developer migrating to SDE for Visual Studio .NET, there are several considerations:

o SDE requires Visual Studio .NET. It is a Visual Studio Integration Package, or VSIP, that plugs into Visual Studio .NET. Unlike eMbedded Visual Basic, SDE cannot operate as a stand-alone product. No additional products are required.

o Smart Device Extensions support both Pocket PC and Pocket PC 2002, Windows CE .NET, and third-party licensees of the .NET Compact Framework.

o SDE is best run under Windows 2000 with Service Pack 2, or Windows XP Professional. While Windows NT is supported, either Windows 2000 or Windows XP is needed for the new true emulator.

NOTE: Windows NT is not supported under the beta of Smart Device Extensions.

o Converting your existing eMbedded Visual Basic applications to Visual Basic .NET is a manual process. You will need to recreate your forms as Windows Forms forms. Your code will need to be modified as well.

o Third-party ActiveX controls that were developed for use with eMbedded Visual Basic will not work with Visual Basic .NET.

o The implementations of the Visual Basic language in Visual Basic .NET and eMbedded Visual Basic are different. You will need to have a solid understanding of Visual Basic .NET and the .NET Compact Framework.

o Certain Visual Basic language keywords will be supported as part of the Microsoft.Visual Basic namespace included with the .NET Compact Framework. This will allow eMbedded Visual Basic developers to use such common statements as MsgBox, InputBox, the Is functions, and standard BASIC string manipulation functions, such as Trim and Instr.

o SDE does not natively support Pocket Access. While it is possible that a third-party vendor may choose to provide this functionality, converting existing eMbedded Visual Basic applications that utilize a Pocket Access database may require moving the data to another source, such as SQL Server CE.

Page 33

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

o Visual Basic .NET-based applications can leverage data binding to quickly build data-enabled applications.

Where to Go from HereGoing from eMbedded Visual Basic to Smart Device Extensions for Visual Studio .NET will require you to learn how to program in Visual Basic .NET and to acquire a solid understanding of the .NET Framework. Reading third-party books on getting started with Visual Basic .NET will aid in shortening your learning curve and will help you get started creating robust mobile applications with SDE.

Page 34

Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET

Appendix A: Functionality Not Included in the .NET Compact FrameworkThis appendix notes some of the key components and functionality that were not included in the .NET Compact Framework.

Features Left Out of the .NET Compact FrameworkTo optimize for size, support for the following features has been excluded from the .NET Compact Framework.

General Functionality Not Included in the Compact FrameworkPrinting. As with eMbedded Visual Basic, printer management and printing APIs will not be supported in the .NET Compact Framework.

MDI forms. Windows CE .NET does not support the Multiple Document Interface (MDI) and, as such, this functionality is not included in the .NET Compact Framework.

GDI+. Windows CE .NET does not support GDI+, so it is not included in the .NET Compact Framework.

Drag-and-drop editing. Windows CE does not support OLE drag-and-drop editing functionality, so it is not included in the .NET Compact Framework.

Binary serialization. Support for binary serialization is not included in the .NET Compact Framework.

XML Functionality Not Included in the .NET Compact Framework

The initial version of the .NET Compact Framework will not support:

XMLDataDocument. This offers a data-friendly document object model (DOM), which makes it easier for developers to work with both relational and nonrelational, or hierarchical, data. Without the XMLDataDocument, developers will need to traverse the document object model manually to access or modify its content.

XMLPathDocument (XPath). XPath enables accessing, selecting, and addressing a node or collection of nodes within an XML document for well known elements and attributes. As in the case with XMLDataDocument, developers will need to code this functionality manually.

XSLTransform (XSLT). XSLT allows a developer to programmatically transform an XML document into another form, whether that form is another XML document, an HTML representation of the data, or a comma-delimited file. Without XSLT, any transformation of XML documents will need to be done with code using the DOM.

Page 35