Escolar Documentos
Profissional Documentos
Cultura Documentos
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Page 2
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Table of Contents
INTRODUCTION
What Is Included with Smart Device Extensions
Why Not eMbedded Visual Basic 4.0?
5
5
6
6
6
7
7
8
8
8
8
9
9
Page 3
9
10
12
13
14
15
16
16
18
19
20
22
23
24
24
25
25
25
26
26
26
26
26
26
26
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
27
27
27
27
27
27
27
28
28
28
28
29
29
31
31
31
32
32
33
33
34
Page 4
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
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.
Page 5
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
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 vendors 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.
The common language runtime is designed to enhance performance. It makes use of Justin-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.
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 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 CEbased 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 thirdparty controls, as well as support for bitmaps and menus.
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.
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.
Page 9
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
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.
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.
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.
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
CheckBox
DomainUpDown
Label
MonthCalendar
ProgressBar
TextBox
TreeView
ColorDialog
ErrorProvider
LinkLabel
NumericUpDown
RadioButton
Timer
VScrollBar
Page 14
ComboBox
GroupBox
ListBox
OpenFileDialog
SaveFileDialog
ToolBar
ContextMenu
HScrollBar
ListView
Panel
StatusBar
ToolTip
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Page 15
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Project Items
While 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
.vb
Bitmap
.bmp
Class
.vb
Code File
.vb
Component Class
.vb
Cursor File
.vb
Page 16
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Custom Control
.vb
Data Form
.vb
Data Set
.xsd
An XSD schema that generates classes you can use to access the
dataset programmatically.
Dynamic Discovery
Document
.vsdisco
Icon File
.vb
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
Module (Visual
Basic only)
.vb
A code file that initially contains a single file for storing functions.
Static Discovery
File
.disco
Text File
.txt
User Control
.vb
Windows Form
.vb
A basic Windows form that you use for local applications. It has a
graphical design surface.
XML File
.xml
XML Schema
.xsd
Page 17
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Configuring Properties
The 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.
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 Code
The 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.
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
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 forms 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
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.
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.
Figure 15. The Visual Studio .NET Configuration Manager dialog box
Page 24
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
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 Images
Not 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 Images
Operating 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 developersaved 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 Functionality
Images 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 Issues
The 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 Environment
One of the benefits of SDE integration within Visual Studio .NET is that SDE can make
use of its native functionalityfor 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 Images
Images 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 Emulator
Unlike 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 Device
As 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.
Page 26
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Default Properties
With 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.
NOTE: Visual Basic .NET supports these new operators in addition to the operators
available in eMbedded Visual Basic.
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
Accessing Data
Visual 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-specificthat 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
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.
Page 31
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
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
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.
Page 34
Embedded Applications - Getting Started with Smart Device Extensions for Visual Studio .NET
Page 35