First Look at Smart Device Extensions
Two for the Road
First Look at Smart Device Extensions

Larry Roof
Tonked.com

October 23, 2001

Last month I mentioned that I was heading out to Microsoft's campus to get a first look at the next version of the compact tools. The purpose of the trip was to provide me with the background foundation I needed to write upcoming magazine articles and books for which I am contracted. Something happened, though, on the way back. I realized that there was no way I could keep this information to myself and not share it with those die-hard Microsoft® eMbedded Visual Basic® developers that regularly read my column.

So I decided to go out to get some legal advice on that supposedly "iron clad" non-disclosure agreement I signed before making the trip—plus I needed a haircut anyways. If I haven't mentioned it before, one of the cool things about working in the Silicon Village—well, that is other than the rippin' 11MB wireless Internet connectivity on the street—is the existence of bi-functional professionals, like Hank, my barber. Hank likes to say, "I could have been a lawyer, but didn't want to waste those eight years in college." Instead, he runs his little barbershop on the fringe of the Silicon Village, doling out free legal advice and haircuts at a bargain price; hence the concept of bi-functional professionals. I think that bi-functional professionals are a real growth industry. Think about it, we are all short on time during the day, not having enough time for work, the kids, plus the other miscellaneous appointments in our lives. The solution is simple—double up on appointments.

For example, you could have car service centers that offer psychiatric care. "Mr. Roof while we are changing the oil and rotating the tires why don't you lay down on the couch?" Or why not fast food restaurants that give advice on your portfolio? "Here is your burger and fries Mr. Roof, and might I say that divesting your tech stocks might be a good idea."

You get my point. The possibilities are endless. But, as usual, I digress. My visit to Hank turned out to be an utter disappointment. First, he told me that non-disclosure agreements are not to be taken lightly. Second, he refused to give me a discount on the cut, even though it is clear that I have less hair to cut than I did ten years ago.

But you know what? I'm going to tell you anyways. Ha, ha, ha—I laugh in the face of authority. For those of you who applaud my nonconformist attitudes, please show your support by making a donation at www.keeproofsbehindoutofjail.com. Without further ado, here is your first look at the next version of the compact tools.

Note   The following section contains graphic, in your face, full-frontal information on the next version of Microsoft's compact tools, and might not be suitable for viewing by teenagers, livestock, or mimes.

Bringing Visual Basic .NET to the Device

It shouldn't be a shock to any of you that the likelihood the next version of the Windows® CE development tools would be based upon .NET was pretty good. I can now tell you that this is in fact true. The next version of the tools will be called Smart Device Extensions for Microsoft Visual Studio® .NET

To the developer experienced with eMbedded Visual Basic, the prospect of having the capabilities offered by Visual Basic .NET available on a mobile platform may seem too good to be true. With the release of Smart Device Extensions for Visual Studio .NET (SDE) Microsoft has done just that. SDE provides a compact version of the .NET Framework, allowing you to build applications in Visual Basic .NET, removing previous limitations that thwarted and restricted mobile developers. With SDE, developers have a tool based upon 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 that 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 of Visual Basic are too great to cover within the confines of this article. Instead, you will be shown a general overview of the .NET Compact Framework, and learn about the new integrated design environment provided by the Smart Device Extension for Visual Studio .NET.

What Is Included with SDE

The Smart Device Extensions 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 standalone. It requires that you have 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 Smart Device Extensions is a set of pre-built device profiles. An embedded device profile contains information necessary to build specific types of applications that target specific devices. For example, there is a profile that enables you to create applications for a Pocket PC, Pocket PC 2002, or "Talisker" using WinForms, ADO .NET, and the ability to consume XML Web services. Other profiles could be provided allowing you to create applications that would target cell phones or third-party personal digital assistants (PDAs).

Profiles may be device specific, such as targeting the Pocket PC, less specific platforms that target the Windows CE platforms in general, or generic profiles that 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 was the case with eMbedded Visual Basic, device kits are separate from SDE and may be installed and updated independently.

Why Not 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 inadequate for advanced development. Based on Microsoft Visual Basic Scripting Edition (VBScript), this engine works well enough for simple applications, but is cumbersome and harbors numerous inadequacies for advanced development needs. eMbedded Visual Basic developers end up spending a significant amount of their time learning tricks and workarounds for limitations inherent within eMbedded Visual Basic. As the popularity of mobile devices has increased, device developers have been requesting a rich, strongly typed, and object oriented Visual Basic development tool, like that found in Visual Basic .NET. They want a tool that will enable them to build wireless solutions that leverage the Internet, Web services and XML. This is what is offered in Smart Device Extensions for Visual Studio .NET. Microsoft has ported the .NET Framework to Windows CE, which enables applications written in 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 technologies, whether you are targeting the .NET Framework or the .NET Compact Framework, you write your applications leveraging functionality provided by the .NET Framework classes, and use the same programming model. In the case of applications developed with SDE, you are targeting the .NET Compact Framework.

What Is in the .NET Compact Framework?

The .NET Compact Framework simplifies application development on smart devices. The .NET Compact Framework has two main components: the Common Language Runtime, or CLR, and the .NET Compact Framework class library.

The CLR 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, such as Visual Basic .NET and C# .NET, is known as managed code; whereas code that does not target the runtime, as is the case with eMbedded 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 steroids.

Note   Managed code, such as is 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 quickly and easily develop applications. This framework is designed in such a manner that it can be ported to other platforms, whether they are created by Microsoft or other vendors. What does this mean to you? Simply that the coding techniques and the applications you create today to run on a Pocket PC could just as easily run on other platforms, such as on a cell phone or on 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 be leveraged on 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. In fact, with Visual Basic .NET's extensive support for data types and structures, you are able to leverage 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 the use of these functions is far less in Visual Basic .NET compared to eMbedded Visual Basic, that capability allows you to create mobile applications that match the functionality found in applications written in eMbedded Visual C++.

The CLR 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 and not have to worry about recompiling or generating executables for each specific platform on which your application will run.

.NET Compact Framework Class Library

The .NET Compact Framework class library is a collection of reusable classes that tightly integrates with the Common Language Runtime. Your Visual Basic .NET 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 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 unsupported 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. This means that you can use your Visual Basic .NET coding techniques in creating both desktop and device applications.

The following section details functionality available through the Smart Device Extensions.

Form-Related Classes

The compact version of the .NET 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 Form designer component of Visual Studio .NET.

The implementation of WinForms under the .NET Compact Framework includes support for forms, most controls found in the .NET Framework, the ability to host third-party controls, and 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, whether the source is a relational or non-relational data source. Working with XML content is straightforward in device applications created in 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, with the most commonly used functionality of both included in the Compact version.

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, using Visual Studio .NET and SDE you can create applications that allow you to consume XML Web services from applications built using Visual Basic .NET.

Note   While Visual Basic .NET targeting the .NET Framework allows you to create both Web Service clients and servers, limitations in the .NET Compact Framework is only a consumer of XML Web Service.

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 as well. The functions included in the Visual Basic Helper library are considered by Visual Basic developers to be a core part of the language, and in fact are comprised of many of the keywords you are experienced with.

The inclusion of the Visual Basic Helper library means that eMbedded Visual Basic developers will be able use many of their favorite Visual Basic statement 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.

GDI Support

The .NET Compact Framework provides support for the basic 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 were limited and cumbersome.

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 multi-threading, leveraging network resources, and working with files.

Features Left Out of the .NET Compact Framework

To limit the size of the .NET Compact Framework, support for the following .NET Framework features have been excluded from the .NET Compact Framework.

  • Printing. As with eMbedded Visual Basic, printer management and printing APIs will not be supported in the .NET Compact Framework.
  • MDI forms. Windows CE does not support the Multiple Document Interface (MDI) and as such this functionality is not included in the .NET Compact Framework.
  • GDI+. Windows CE does not support GDI+, so they are not included in the .NET Compact Framework.
  • Drag-and-drop functionality. Windows CE does not support OLE drag-and-drop functionality, so it was not included in the .NET Compact Framework.
  • Binary serialization. Support for binary serialization is not included in the .NET Compact Framework.

The 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 integrated development environment, or IDE, that Visual Studio .NET provides. 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 Window CE 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

Clicking the New Project button causes the New Project dialog to be displayed, as shown in Figure 2. From this dialog you can select a template from which to create your application. Smart Device Extensions installs a set of templates in both the Visual Basic and Visual C# project folders.

SDE installs four templates in the Visual Basic Projects folder. The Pocket PC Application template provides the basic project configuration required for creating a Pocket PC application. This project template is highlighted in Figure 2.

Figure 2 shows two additional Pocket PC-related templates. The Pocket PC Class Library template is used to construct class libraries. The Pocket PC Control Library template is used to create controls.

NOTE   The addition of control and class libraries to Visual Basic .NET is a significant enhancement over eMbedded Visual Basic, where neither of these functionalities is supported.

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

The fourth template included with SDE is the Windows CE Application template, as shown in Figure 3. This template enables you to build a .NET Compact Framework project that targets any device running Windows CE that supports the .NET Compact Framework.

Figure 3. The New Project dialog 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 Interface

If you have experience working with Visual Studio .NET, you will require little orientation to begin working with the Smart Device Extensions. For eMbedded Visual Basic developers just starting with .NET, the following section leads you through the key features of the Visual Studio .NET IDE.

Upon creating a new project, the Start Page will be replaced with a blank form as shown in Figure 4.

Figure 4. The Windows Form designer

At first glance, this part of the Visual Studio .NET IDE appears similar to the form designer in eMbedded Visual Basic. Upon 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].

We have already looked at the Start Page, but what about the two Form1.vb tabs? These two tabs correlate to the eMbedded Visual Basic 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 using these tabs.

The New Toolbox

The Toolbox in the Visual Studio .NET IDE is located in the same general location as it is 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 provides for more available screen space when designing forms and writing code.

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

Figure 5. The Visual Studio .NET toolbox in its hidden state

Figure 6. The Visual Studio .NET toolbox in its visible state

Controls Provided with Smart Device Extensions

While eMbedded Visual Basic provides a limited set of controls, Smart Device Extensions 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 ContextMenu
DateTimePicker DomainUpDown ErrorProvider GroupBox HScrollBar
ImageList Label LinkLabel ListBox ListView
MainMenu MonthCalendar NumericUpDown OpenFileDialog Panel
PictureBox ProgressBar RadioButton SaveFileDialog StatusBar
TabControl TextBox Timer ToolBar ToolTip
TrackBar TreeView VScrollBar    

Table 1. The controls included with Smart Device Extensions

Adding Controls to Your Form

Working 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 7, a button has been added to a form. Visual Studio .NET offers a complete set of user interface configuration tools under the Format menu, including align, size, space, center and lock in position.

Figure 7. Adding a button to a form

Managing Your Project

You 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 8, is used to access and configure your project and its components.

Figure 8. The Visual Studio .NET Solution Explorer window

Project Items

eMbedded Visual Basic was incredibly limited in the scope of its supported project items, with only form and standard modules. Smart Device Extensions for Visual Studio .NET, however, provides a broad set of project items from which to choose. Table 2 details the supported items along with their file extension and a brief description.

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 for creating 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; it contains no code.
Component class .vb A class (a business object) for which a visual designer exists.
Cursor file .vb An image file for creating custom cursors.
Custom control .vb A Windows control that is not visually designed, that is, which 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 for the dataset that you can use to access the data 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 Similar to a User Control except that it 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 a 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 with Smart Device Extensions

Configuring Properties

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

Figure 9. 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.

Adding Code

The Visual Studio .NET code window, as shown in Figure 10, is similar to the eMbedded Visual Basic version. The main editing area includes the added functionality of being able 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 allows you to select an object. The combo box at the top right of the code window allows you to select a method, where eMbedded Visual Basic allows you to select a procedure. The Visual Studio .NET Code Window supports robust statement completion, including auto listing members and providing parameter information.

Figure 10. The Visual Studio .NET code window demonstrating Microsoft® 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 end 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.

The Code Behind a Visual Basic .NET Form

When 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, where form definitions were described separately from the form's code.

The Windows Form Designer automatically generates this code, adds it to the form's code module as shown in Figure 11. 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 11. Code with generated code hidden

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

Figure 12. Code with generated code exposed (note the form and control definitions)

Configuring Your Project

Project properties are configured through the Property Pages dialog. This dialog can be accessed by clicking Properties under the Project menu, or by right-clicking on your project in the Solution Explorer, and then clicking Properties from the popup menu as shown in Figure 13.

Figure 13. Accessing project properties

The Property Pages dialog, shown in Figure 14, 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 14. Configuring project properties

Building Your Application

To build an application, click Build from under the Build menu. If it is not already displayed, the Output Window will appear as shown in Figure 15.

Figure 15. 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 folder, file information, and memory usage. Exception handling information includes connection time out, insufficient memory, path not found, access denied, sharing violation, cancelled deployments, and other unexpected errors. Status information includes successes, failures, and items that are skipped. Reference the Output Window to aid in the resolution of compilation and deployment issues.

Testing Your Application

Like eMbedded Visual Basic, Smart Device Extensions allows 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 Studion .NET IDE provide a menu bar interface, as shown in Figure 16, which allows you to select the target for testing.

Figure 16. Selecting a deployment target

Summary of My First Look at SDE

I have to tell you that I am nothing but stoked about the future of Visual Basic-based development under the Windows CE operating system. After years of trying to make first Visual Basic for CE and then eMbedded Visual Basic do what I wanted it to do, there is a cool, powerful alternative that will soon be available. Look for an SDE beta in the near future, and hone up on your Visual Basic .NET skills. You will need them to make the transition.

Back on the Road

That's it for this month. I hope you can see now why I couldn't keep this information to myself. Look for more articles in the coming months that will get away from the theory part of SDE and into the nut-and-bolt side of creating applications with this powerful new tool. This month has me heading to Los Angeles, to speak at the PDC on moving from eMbedded Visual Basic to SDE, and to get in some much-needed surfing. Until then, I'm back on the road.

 

John Kennedy is a Technical Writer/Programmer in the Visual C++ group by day and leads a secret life as a Pocket PC developer by night.

Larry Roof is a partner at tonked, a firm that specializes in the development of mobile solutions and training. He's the author of Professional Visual Basic Windows CE, available from Wrox Press.

Page view tracker