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.

Table of Contents

Introduction

What Is Included with Smart Device Extensions

Why Not eMbedded Visual Basic 4.0?

The .NET Compact Framework

What Is in the .NET Compact Framework?

Features of the Common Language Runtime

.NET Compact Framework Class Library

Form-Related Classes

Data and XML Classes

Web Services

Visual Basic Support

GDI Support

Base Classes

Using The Development Environment

Creating a New Project

Constructing a User Interface

The New Toolbox

Controls Provided with Smart Device Extensions

Adding Controls to Your form

Managing Your Project

Project Items

Configuring Properties

Adding Code

The Code Behind a Visual Basic .NET Form

Configuring Your Project

Building Your Application

Configuration Manager Dialog Box

Testing Your Application

The Smart Device Extensions Emulator

Working with Emulator Images

Saving and Restoring Images

Image Functionality

Localization Issues

Automated Testing Environment

Obtaining Additional Images

Summary of the New Emulator

Testing on a Device

Remote Tools Included with SDE

Differences between eMbedded Visual Basic and Visual Basic .NET

Variant Is No Longer Supported

Integer Data Types

Declaring Values While Dimensioning a Variable

Fixed-Length Strings Are Not Supported

Use Zero Bound Arrays

Default Properties

Subs and Functions Require Parentheses

Optional Arguments Are Not Allowed

New Assignment Operators

New Error Handling

Support for APIs

Accessing Data

What Are Datasets?

Visual Basic .NET Compact and XML

XML Functionality Included Under the .NET Compact Framework

Local Data Storage Using XML

Working with Files Under SDE

Working with XML Web Services

Getting Started with Smart Device ExtensionS

Where to Go From Here

Appendix A – Functionality not included in the .NET Compact Framework

Features Not Included in the .NET Compact Framework

General Functionality Not Included in the .NET Compact Framework

XML Functionality Not Included in the .NET Compact Framework

Introduction

To 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 Extensions

SDE 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.

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 Framework

Any 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 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 Runtime

The 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 Library

The .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 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 Classes

The .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 Classes

The .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 Services

The .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 Support

Visual 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.

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 Support

The .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 Classes

The .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 Environment

Smart 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.

Creating a New Project

When 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

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.