(459 KB) Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
Programming the .NET Compact Framework
By Paul Yao & David Durant
Chapter 1
Compact Framework Architecture
The .NET Compact Framework is a programming interface and runtime library created as a
combination of two Microsoft technologies: Windows CE, an operating system for mobile and
embedded 'smart devices', and .NET, Microsoft's reinvention of its programming interfaces and its
developer tools. This chapter covers key elements of Windows CE and key elements of .NET to show
how they come together in the .NET Compact Framewor k [Comment 1.1] .
Windows CE Overview
What is .NET?
The .NET Compact Framework
Chapter 1 – Architecture
Page 1
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework
By Paul Yao & David Durant
In the early 1990's – Microsoft declared that two technologies were core to its long-term
strategic plans: Win32 and COM 1 . Microsoft created Win32, the 32-bit Windows Application
Programming Interface (API), as a successor to its then-dominant Win16 API. COM, Microsoft's
component software architecture, was introduced as a way to snap together software components
in a fashion analogous to the way that electronic integrated circuits are snapped together.
The first version of Windows CE shipped in 1996, with the Win32 API at its core. Windows
CE is Microsoft's only operating system with Win32 as the primary API for both application
development and device driver developmen t 2 . In some respects, Windows CE was developed as a
smaller, lightweight version of Microsoft's 32-bit operating systems – a kind of Windows XP-
Lite. But Windows CE shares little if any code with the heavier desktop operating systems,
having been written from scratch to address the needs of hardware and software engineers
working to develop mobile and embedded smart devices. On Windows CE today, Win32 is still a
valid option for application development. In some cases, Win32 provides the only way to
accomplish some things. [Comment 1.3]
COM provides the building blocks for a wide range of components. COM first supported
compound documents, the Object Linking and Embedding (OLE) specification. OLE provides the
ability to embed an object such as a spreadsheet or a bitmap into a container document, such as a
word processing document. COM was renamed to ActiveX when the Internet Explorer, and its
support for ActiveX controls, was introduced. COM/ActiveX components allow third-parties to
add new components – in the form of controls, plug-ins, and other kinds of extensions . [Comment
COM provides the glue for connecting together components. As such, it addresses some
critical development issues, including code-reuse and programmer productivity. But COM is
complex and quirky, requiring both developers and consumers of components to handle
administrative chores which would be better handled if automated. For example, COM
components must track connections to external clients with a reference count. Although simple in
principle, COM programming in practice requires a serious investment of time and energy to
When the .NET initiative was announced in 2000, it heralded a replacement for both Win32
and COM. While Microsoft would continue adding Win32 extensions to its various operating
systems, the Win32 would no longer be the core programming interface. That role would fall to
the .NET Framework on desktop versions of Windows, and the .NET Compact Framework on
Windows CE platforms such as the Pocket PC. And while support for COM would continue 3 , the
1 COM = 'Component Object Model', an architecture for building distributed components.
2 By contrast, other members of the Microsoft Windows operating system family use either VxDs
(for Windows 95, 98, Me) or a kernel-mode driver interface (for Windows NT, 2000, XP, and 2003
Server) that is decidedly not the Win32 API.
3 The .NET Framework supports COM with a feature referred to as COM Interop . Version 1.0 of
the Compact Framework has no COM support; a future version will add COM interop support.
Chapter 1 – Architecture
Page 2
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework
By Paul Yao & David Durant
role of new software components would be played by .NET assemblies and not by COM
components. [Comment 1.6]
The .NET Compact Framework brings the technologies of the .NET Framework to the mobile
and embedded world of Windows CE. To better understand the dynamic of this mix, this chapter
starts with a discussion of Windows CE. We next look at the broader scope of .NET as
implemented in the .NET Framework with its support for Windows Forms, Web Forms, and
XML Web services. We conclude the chapter with a discussion of the Compact Framework –
what it is, how it works, and where it is going. [Comment 1.7]
Windows CE Overview
As of this writing, the Pocket PC is the most successful Windows CE-powered device. As a
result of that success, Compact Framework supports all versions of the Pocket PC, including the
first two generations which are built on Windows CE 3.0 (Pocket PC 2000 and the Pocket PC
2002). This is noteworthy because, except for the Pocket PC, all Windows CE-powered platforms
must run Windows CE version 4.2 or later to support the Compact Framework. (The third
generation of Pocket PC, the Pocket PC 2003, runs this later version of the operating system. )
To many people, Pocket PC and Windows CE are one and the same. But that view misses the
point about Windows CE's wider impact and how it addresses the needs of the embedded world.
Windows CE is the foundation for a wide range of other smart devices, including the
SmartPhone. As we were finishing this book in the summer of 2003, Microsoft launched a
marketing campaign with a new brand – Windows Mobile Devices – to tie the Pocket PC and the
SmartPhone together as mobile extensions to the Windows brand name. [Comment 1.9]
Beyond the Pocket PC and the SmartPhone, many other smart devices are powered by
Windows CE, including barcode scanners from companies like Intermec, Psion Teklogix, and
Symbol Technologies, smart displays from companies like View Sonic and Philips, and
automobile-based navigation and entertainment systems – running CE for Automotive – in cars
from BMW (developed by Siemens VDO Automotive AG), Citroen, Fiat, Mitsubishi, Subaru,
Toyota and Volvo . [Comment 1.10]
Because the Pocket PC and Windows CE are connected in the minds of so many, developers
new to Windows CE often assume that a required Pocket PC feature is also required for all
Windows CE devices. But Windows CE is a highly configurable operating system, with hundreds
of system components and device drivers to choose from. While many Windows CE-powered
devices have display screens, headless configurations – such as network routers and set-top boxes
– are also possible. Many CE-powered smart devices run as mobile, battery-powered devices; but
wall-powered, stationary smart devices are also possible, and Windows CE has been incorporated
into Automatic Teller Machines (ATMs) and computer printers. And while some Windows CE-
powered devices rely solely on RAM with no rotating storage media, Windows CE supports ATA
drives and other installable file systems to extend available storage beyond what is available in the
object store 4 . [Comment 1.11]
We wrote our sample code for the Pocket PC
Because of the success of the Pocket PC, we wrote this book expecting
that Pocket PC programmers would make up the majority of our readers.
Most of our examples, in fact, are built for quarter-VGA portrait-mode
4 The object store is a RAM-based storage area with three elements: a file system, registry, and
the CEDB property databases. These are discussed in detail in chapter 11, Storage .
Chapter 1 – Architecture
Page 3
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework
By Paul Yao & David Durant
display screens – the size and orientation which, up until the present, has
been standard on a Pocket PC. [Comment 1.12]
For developers writing programs for devices other than Pocket PC, all of
our samples should run with few if any changes. The only thing needed is
that a platform be compatible with the Compact Framework, either
installed in ROM or at runtime into the object store. [Comment 1.13]
Design Goals
When starting to look at any technology, it helps to know what the creators of the technology
had in mind during their development process. We start, then, with a discussion of the design
goals for Windows CE. We have found that each design goal has a real impact on what an
application programmer can do, and that understanding these design goals help to understand a
wide range of choices made by the Windows CE development teams. [Comment 1.14]
We learned about these design goals through discussions with the original Windows CE
development team. These design goals still play an important role, because they describe the
requirements which subsequent development teams have followed as they enhanced and fine-
tuned this operating system: [Comment 1.15]
The first design goal is also the most important: Windows CE was built to be small. The
smallest Windows CE image is less than 500K – the tiny kernel that has no display screen and no
device drivers. By itself, the tiny kernel image supports a file system, can run processes, start
threads, load dynamic link libraries, and access memory. The tiny kernel does not support enough
of the Win32 API to support the Compact Framework, but is certainly enough for simple devices
like a dumb printer, or a portable music player. [Comment 1.16]
A more typical device image might occupy 5 or 10 megabytes of RAM – enough to support a
display screen and enough network protocols to run a web browser. Devices such as the Pocket
PC might have a 32 megabyte (or larger) ROM image, consisting largely of application programs
and optional device drivers. [Comment 1.17]
This is not small by the standards of other embedded operating systems, which might have a
minimum footprint even smaller than the tiny kernel. What Windows CE does provide, however
is a feature-rich, configurable operating system. By way of comparison, consider the various
desktop versions of Windows. Windows Me, for example, requires 100 megabytes of disk space;
Windows XP requires 500 megabytes of disk space. In the Microsoft Windows family of
operating systems, Windows CE is definitely the very small – and very flexible – sibling .
The emphasis on making Windows CE small was to reduce the required hardware, thereby
making Windows CE a good fit for high-volume, low-cost consumer electronic devices. In that
highly competitive market, development teams work hard to reduce costs by scaling back on the
required hardware – the RAM, the ROM, the CPU, and the myriad components – because lower
costs create a competitive advantage in the price conscious world of consumer electronics.
Chapter 1 – Architecture
Page 4
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework
By Paul Yao & David Durant
The 'small-is-good' mindset for Windows CE mostly affects developers who come to
Windows CE with Win32 or .NET Framework experience from desktop versions of Windows.
Such programmers often have an experience that we call 'stubbing your toe,' which occurs when a
programmer new to Windows CE starts to get comfortable with whatever API they are using. Just
when they think they have device-side programming figured out, they find they want to use an
old familiar friend from the desktop that is not implemented under Windows CE. It might be a
Win32 function call. It could be a .NET Framework namespace, class, property, method, or event.
At first, these can be frustrating experiences – making one wonder what global conspiracy has
deprived you of your favorite way to do some common task. In most cases, there is another way
to accomplish what you need done. To make sense of the omission, it helps to remember that
small is good, and that Windows CE was built to be a small operating system. [Comment 1.20]
Microsoft's Compact Framework team followed this design goal. The first version of the
Compact Framework occupies less than 2 megabytes 5 . This compares to the 30+ megabytes
which are occupied by the .NET Framework on desktop versions of Windows. [Comment 1.21]
Windows CE is modular, a quality that is necessary because Windows CE is configurable.
Unlike desktop versions of Windows, which are developed and which ship as a monolithic set of
files, Windows CE itself is made up of modules (programs as .exe files, and libraries as .dll files),
and some modules are made up of two or more components (each of which consists of Win32
functions or operating system features). [Comment 1.22]
When a development team designs a new device, they use a tool from Microsoft called
Platform Builder . Platform Builder allows a third-party to customize the operating system image
by adding or removing various modules as needed for their custom smart device. Building a
platform which needs a file-open and file-save dialog box? There is a module for that. Need this
display driver or that network driver? Platform Builder lets you fine-tune the elements of an
operating system image so that you have just the set that you need. Among available Platform
Builder components is the Compact Framework itself, which means that custom devices can
include the Compact Framework in its ROM 6 image. The Pocket PC 2003 platform, for example,
includes the Compact Framework as a built-in component. [Comment 1.23]
Pocket PC and the Platform Builder
The subject of Pocket PC and the Platform Builder often raises questions
for smart device developers. Can the Platform Builder be used to create a
custom image for a Pocket PC? Generally speaking, the answer is no.
Only developers with a special Pocket PC-specific version of the Platform
Builder can create a custom Pocket PC operating system image. The
security of Pocket PC devices is further insured because the ability to
install a new operating system image on a given platform normally
requires special knowledge of that platform. [Comment 1.24]
In our training classes, we often get asked about the difference between a Pocket PC and a
custom embedded device built with the Platform Builder. The short answer is that the core
operating system is the same, and so porting software between a Pocket PC and other Windows
CE devices is very doable. For Win32 programs, the key issue is the available set of functions
that are supported on each device. Assuming that two Windows CE-powered devices support the
5 The actual size depends on the CPU and whether files are compressed or not. ROM-based files
have the option of being compressed, and files in the RAM-based file system are always
compressed with a fast-but-light compression algorithm that yields a 2:1 compression ratio.
6 ROM = Read-Only-Memory. A device manufacturer might use ROM, although or flash memory
is often used. The benefit of flash memory is that field upgrades can often be accomplished
without opening a device's physical case.
Chapter 1 – Architecture
Page 5
Copyright © 2003 Paul Yao & David Durant
Zgłoś jeśli naruszono regulamin