100% found this document useful (2 votes)
19 views

[FREE PDF sample] Programming Microsoft Windows CE NET 3rd Edition Douglas Boling ebooks

Programming

Uploaded by

dyksasazaric
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
19 views

[FREE PDF sample] Programming Microsoft Windows CE NET 3rd Edition Douglas Boling ebooks

Programming

Uploaded by

dyksasazaric
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Visit https://ebookgate.

com to download the full version and


explore more ebooks

Programming Microsoft Windows CE NET 3rd Edition


Douglas Boling

_____ Click the link below to download _____


https://ebookgate.com/product/programming-microsoft-
windows-ce-net-3rd-edition-douglas-boling/

Explore and download more ebooks at ebookgate.com


Here are some recommended products that might interest you.
You can download now and explore!

Professional Microsoft Windows Embedded CE 6 0 Samuel


Phung

https://ebookgate.com/product/professional-microsoft-windows-embedded-
ce-6-0-samuel-phung/

ebookgate.com

Microsoft Jscript NET Programming Justin Rogers

https://ebookgate.com/product/microsoft-jscript-net-programming-
justin-rogers/

ebookgate.com

Programming Microsoft ADO NET 2 0 Core Reference David


Sceppa

https://ebookgate.com/product/programming-microsoft-ado-net-2-0-core-
reference-david-sceppa/

ebookgate.com

Programming the Microsoft Windows Driver Model 2nd Edition


Walter Oney

https://ebookgate.com/product/programming-the-microsoft-windows-
driver-model-2nd-edition-walter-oney/

ebookgate.com
MCTS Self Paced Training Kit Exam 70 502 Microsoft NET
Framework 3 5 Windows Presentation Foundation Matthew A.
Stoecker
https://ebookgate.com/product/mcts-self-paced-training-kit-
exam-70-502-microsoft-net-framework-3-5-windows-presentation-
foundation-matthew-a-stoecker/
ebookgate.com

Microsoft Windows XP Inside Out Ed Bott

https://ebookgate.com/product/microsoft-windows-xp-inside-out-ed-bott/

ebookgate.com

Special edition using Microsoft Windows Vista Robert


Cowart

https://ebookgate.com/product/special-edition-using-microsoft-windows-
vista-robert-cowart/

ebookgate.com

Microsoft Access VBA programming for the absolute beginner


3rd Edition Michael (Michael Vine) Vine

https://ebookgate.com/product/microsoft-access-vba-programming-for-
the-absolute-beginner-3rd-edition-michael-michael-vine-vine/

ebookgate.com

Programming Visual Basic 2008 Build NET 3 5 Applications


with Microsoft s RAD Tool for Business 1st Edition Tim
Patrick
https://ebookgate.com/product/programming-visual-basic-2008-build-
net-3-5-applications-with-microsoft-s-rad-tool-for-business-1st-
edition-tim-patrick/
ebookgate.com
PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399

Copyright 2003 by Douglas Boling

All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or
by any means without the written permission of the publisher.

Library of Congress Cataloging-in-Publication Data


Boling, Douglas McConnaughey, 1960-
Programming Microsoft Windows CE .NET / Douglas Boling.--3rd ed.
p. cm.
Includes index.
ISBN 0-7356-1884-4
1. Microsoft Windows (Computer file) 2. Operating systems (Computers) 3. Microsoft
.NET. I. Title.

QA76.76.O63B625 2003
005.4'469--dc21 2003042205

Printed and bound in the United States of America.

123456789 QWT 876543

Distributed in Canada by H.B. Fenn and Company Ltd.

A CIP catalogue record for this book is available from the British Library.

Microsoft Press books are available through booksellers and distributors worldwide. For further information
about international editions, contact your local Microsoft Corporation office or contact Microsoft
Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send
comments to [email protected].

ActiveSync, ActiveX, Developer Studio, DirectX, Microsoft, Microsoft Press, MS-DOS, Visual Basic,
Visual C++, Visual C#, Visual Studio, Win32, Windows, Windows NT, and Windows Server are either
registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
Other product and company names mentioned herein may be the trademarks of their respective owners.

The example companies, organizations, products, domain names, e-mail addresses, logos, people,
places, and events depicted herein are fictitious. No association with any real company, organization,
product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred.

Acquisitions Editor: Anne Hamilton Interior Artist: Michael Kloepfer


Project Editor: Kathleen Atkins Proofreader: nSight, Inc.
Technical Editor: Jim Fuchs Indexer: Julie Hatley
Interior Graphic Designer: James D. Kramer Cover Designer: Methodologie, Inc.
Principal Compositor: Dan Latimer

Body Part No. X09-39008


To Nancy Jane
Acknowledgments
Books are produced by diverse teams of talented people. My name appears on the cover, but countless
others were involved in this book’s creation. The teams of people who worked on this edition all
pushed themselves to the max to complete this revision.

First, there’s the talented team at Microsoft Press. Kathleen Atkins, the project leader and editor of all
three editions of this book, took my gnarled syntax and confused text and made it readable. The
technical editor for this edition, as well as the first edition of the book, was Jim Fuchs. Jim provided a
great sanity check for me as well as providing a huge amount of help in getting the CD organized and
produced. Shawn Peck performed the copyediting duties, keeping the text within the rules of the
English language. Dan Latimer performed the desktop publishing duties, and Michael Kloepfer
produced the illustrations. Thanks to Julie Hatley for the index. Anne Hamilton, who was the
acquisitions editor for both the second and third editions of the book, deserves credit for getting these
revisions released. Thanks, Anne, for all your efforts in keeping this book up-to-date.

Thanks also to the various Microsoft development and marketing teams. Over the years, they have
tolerated my endless questions. Thanks to Mike Thomson, Michael Malueg, and Andrew Pearson for
answering questions and reviewing chapters. Ori Amiga on the Pocket PC team provided all manner of
priceless assistance: answering questions, getting new builds, and even providing hardware. Thanks
also to Dominique Fortier, who provided great assistance on the Pocket PC, Bluetooth, and OBEX
content in this edition. I had great support from the Compact Framework team from Craig Neable,
Mark Gilbert, and Kei Amos. A special thank-you goes to Jeana Jorgensen, who, across a variety of
jobs at Microsoft, has always tolerated my cries for help no matter the hour or relevance to her job.
Thanks to all of you. Your help made this book so much better than it would have been without you.

I also need to acknowledge Tatia Meghdadi, John Doub, and the team at Socket Communication, who
provided Bluetooth hardware and software for testing.

A special thanks goes to my agent, Claudette Moore, and the team at Moore Literary Agency.
Claudette handled all the business details, freeing me to deal with the fun stuff.

This edition of Programming Windows CE builds on the foundation of the two earlier editions, so what
you read is based on work from a much larger team. In addition to the people already mentioned, other
folks from Microsoft Press have helped immensely in the editing and production of the earlier editions
of the book. They include Brian Johnson, Julie Xiao, Rebecca McKay, Rob Nance, Cheryl Penner,
Elizabeth Hansford, and Michael Victor.

My personal support team is headed by my wife, Nancy. Thanks, Nancy, for the support, help, and
love. The personal support team also includes our boys, Andy, Sam, and Jake. They make sure I
always remember what is important in life. I also must acknowledge my parents, Ronald and Jane
Boling. They are my role models.
Introduction
I’ve been working with Microsoft Windows CE for almost as long as it’s been in existence. A
Windows programmer for many years, I’m amazed by the number of different, typically quite small,
systems to which I can apply my Windows programming experience. These Windows CE systems run
the gamut from PC-like mini-laptops to cellular phones to embedded devices buried deep in some large
piece of industrial equipment. The use of the Win32 API in Windows CE enables tens of thousands of
Windows programmers to write applications for an entirely new class of systems. The subtle
differences, however, make writing Windows CE code somewhat different from writing for the
desktop versions of Windows. It’s those differences that I’ll address in this book.
Just What Is Windows CE?

Windows CE is the smallest and arguably the most interesting of the Microsoft Windows operating
systems. Windows CE was designed from the ground up to be a small ROM-based operating system
with a Win32 subset API. Windows CE extends the Windows API into the markets and machines that
can’t support the larger footprints of the Windows XP kernel.

The now-defunct Windows 95/98/Me line was a great operating system for users who needed
backward compatibility with MS-DOS and Windows 2.x and 3.x programs. Although it had
shortcomings, Windows Me succeeded amazingly well at this difficult task. The Windows
NT/2000/XP line, on the other hand, is written for the enterprise. It sacrifices compatibility and size to
achieve its high level of reliability and robustness. Windows XP Home Edition is a version of
Windows XP built for the home user that does strive for compatibility, but this is secondary to its
primary goal of stability.

Windows CE isn’t backward compatible with MS-DOS or Windows. Nor is it an all-powerful


operating system designed for enterprise computing. Instead, Windows CE is a lightweight,
multithreaded operating system with an optional graphical user interface. Its strength lies in its small
size, its Win32 subset API, and its multiplatform support.

Windows CE also forms the foundation for the initial version of the .NET Compact Framework, a
version of the .NET runtime for mobile and embedded devices. The Compact Framework provides the
same powerful .NET runtime environment with a smaller class library so that it fits in small battery-
powered devices.
A Little Windows CE History

To understand the history of Windows CE, you need to understand the differences between the
operating system and the products that use it. The operating system is developed by a core group of
programmers inside Microsoft. Their product is the operating system itself. Other groups, who develop
devices such as the Pocket PC, use the newest version of the operating system that’s available at the
time their product is to be released. This dichotomy has created some confusion about how Windows
CE has evolved. Let’s examine the history of each, the devices and the operating system itself.

The Devices

The first products designed for Windows CE were handheld “organizer” devices with 480-by-240 or
640-by-240 screens and chiclet keyboards. These devices, dubbed Handheld PCs, were first introduced
in late 1996. Fall Comdex 97 saw the release of a dramatically upgraded version of the operating
system, Windows CE 2.0, with newer hardware in a familiar form—this time the box came with a 640-
by-240 landscape screen, sometimes in color, and a somewhat larger keyboard.

In January 1998 at the Consumer Electronics Show, Microsoft announced two new platforms, the
Palm-size PC and the Auto PC. The Palm-size PC was aimed directly at the pen-based organizer
market dominated by Palm OS–based systems. The Palm-size PC featured a portrait mode and a 240-
by-320 screen, and it used stylus-based input. Unfortunately for Windows CE fans, the public
reception of the original Palm-size PC was less than enthusiastic.

Later that year, a new class of mini-laptop–style Windows CE machines with touch-typable keyboards
and VGA or Super VGA screens made their appearance. These machines, called H/PC Professionals,
provided 10 hours of battery life combined with improved versions of Microsoft’s Pocket Office
applications. Many of these machines had built-in modems, and some even diverged from the then-
standard touch screen, sporting track pads or IBM’s TrackPoint devices.

In April 2000, Microsoft introduced the Pocket PC, a greatly enhanced version of the old Palm-size
PC. The original Pocket PC used a prerelease of the more full-featured Windows CE 3.0 operating
system under the covers. The user interface of the Pocket PC was also different, with a cleaner, 2D,
look and a revised home page, the Today screen. The most important feature of the Pocket PC,
however, was the greatly improved performance of Windows CE. Much work had been done to tune
Windows CE for better performance. That improvement, coupled with faster CPUs, allowed the system
to run with the zip expected from a pocket organizer. With the Pocket PC, the inevitability of Moore’s
Law enabled Windows CE devices to cross over the line: the hardware at this point was now capable
of providing the computing power that Windows CE required.

The Handheld PC was updated in 2000 to use Windows CE 3.0. Although these systems (now called
the Handheld PC 2000) haven’t been a consumer success, they have found a home in the industrial
market, where their relative low cost, large screens, and great battery life satisfy a unique niche market.

The Pocket PC was updated in late 2001 with a release named Pocket PC 2002. This release was based
on the final released version of Windows CE 3.0 and contained some user interface improvements. An
exciting development was the addition of the Pocket PC Phone Edition, which integrated cellular
phone support into a Pocket PC device. These devices combined the functionality of a Pocket PC with
the connectivity of a cellular phone, enabling a new generation of mobile but always connected
software.

Another group within Microsoft released the Smart Display, a Windows CE .NET 4.1–based system
that integrated a tablet form factor device with wireless networking and a base connected to a PC.
When the Smart Display is in its base, it’s a second monitor; when removed, it becomes a mobile
display for the PC.

In the spring of 2003, the Pocket PC team released an update of the Pocket PC called the Pocket PC
2003. This system, while not providing much of a change to the user interface, did provide a huge
increase in stability and performance because it was based on Windows CE .NET 4.2. The Pocket PC
2003 also added integrated Bluetooth support for those OEMs that chose to include it.

Microsoft has also been working with OEMs to produce cellular phones based on Windows CE. A
smattering of these phones, called Smartphones, were released in late 2002 and were initially based on
Windows CE 3.0. An upgrade in 2003 moved the Smartphone to Windows CE 4.2 and increased the
feature set of the device to include the .NET runtime.

New devices are being introduced all the time. An example are the Media to Go devices, which are
mobile video players using a hard disk for storage. The power of the Windows CE operating system
enables applications that are beyond the capability of systems with simpler operating systems to run on
these devices.

The Operating System

Although these consumer-oriented products made the news, more important development work was
going on in the operating system itself. The Windows CE operating system has evolved from the days
of 1.0, when it was a simple organizer operating system with high hopes. Starting with Windows CE
2.0 and continuing to this day, Microsoft has released embedded versions of Windows CE that
developers can use on their custom hardware. Although consumer platforms such as the Pocket PC get
most of the publicity, the improvements to the base operating system are what enable devices such as
the Pocket PC and the Smartphone.

Windows CE 2.0 was released with the introduction of the Handheld PC 2.0 at Fall Comdex 1997.
Windows CE 2.0 added networking support, including Windows standard network functions, a
Network Driver Interface Specification (NDIS) miniport driver model, and a generic NE2000 network
card driver. Added COM support allowed scripting, although the support was limited to in-proc
servers. A display driver model was also introduced that allowed for pixel depths other than the
original 2-bits-per-pixel displays of Windows CE 1.0. Windows CE 2.0 was also the first version of the
operating system to be released separately from a product such as the H/PC. Developers could
purchase the Windows CE Embedded Toolkit (ETK), which allowed them to customize Windows CE
to unique hardware platforms. Developers who used the ETK, however, soon found that the goal of the
product exceeded its functionality.

With the release of the original Palm-size PC in early 1998, Windows CE was improved yet again.
Although Windows CE 2.01 wasn’t released in an ETK form, it was notable for its effort to reduce the
size of the operating system and applications. In Windows CE 2.01, the C runtime library, which
includes functions such as strcpy to copy strings, was moved from a statically linked library attached to
each EXE and DLL into the operating system itself. This change dramatically reduced the size of both
the operating system and the applications themselves.

In August 1998, Microsoft introduced the H/PC Professional with a new version of the operating
system, 2.11. Windows CE 2.11 was a service pack update to Windows CE 2.1, which was never
formally released. Later in the year, Windows CE 2.11 was released to the embedded community as
Microsoft Windows CE Platform Builder version 2.11. This release included support for an improved
object store that allowed files in the object store to be larger than 4 MB. This release also added
support for a console and a Windows CE version of CMD.exe, the classic MS-DOS–style command
shell. Windows CE 2.11 also included Fast IR to support IrDA’s 4-MB infrared standard, as well as
some specialized functions for IP multicast. An initial hint of security was introduced in Windows CE
2.11: a device could now examine and reject the loading of unrecognized modules.

Windows CE 2.12 was also a service pack release to the 2.1, or Birch, release of Windows CE. The big
news in this release was a greatly enhanced set of Platform Builder tools that included a graphical front
end. The operating system was tweaked with a new notification interface that combined the disparate
notification functions. The notification user interface was exposed in the Platform Builder to allow
embedded developers to customize the notification dialog boxes. A version of Microsoft’s PC-based
Internet Explorer 4.0 was also ported to Windows CE as the Genie, or Generic IE control. This HTML
browser control complements the simpler but smaller Pocket Internet Explorer. Microsoft Message
Queue support was added as well. The “go/no go” security of Windows CE 2.11 was enhanced to
include a “go, but don’t trust” option. Untrusted modules can run—but not call—a set of critical
functions, nor can they modify parts of the registry.

The long-awaited Windows CE 3.0 was finally released in mid-2000. This release followed the April
release of the Pocket PC, which used a slightly earlier internal build of Windows CE 3.0. The big news
for Windows CE 3.0 was its kernel, which was optimized for better real-time support. The enhanced
kernel support includes 256 thread priorities (up from 8 in earlier versions of Windows CE), an
adjustable thread quantum, nested interrupt service routines, and reduced latencies within the kernel.

The improvements in Windows CE 3.0 didn’t stop at the kernel. A new COM component was added to
complement the in-proc COM support available since Windows CE 2.0. This new component included
full COM out-of-proc and DCOM support. The object store was also improved to support up to 256
MB of RAM. File size limits within the object store were increased to 32 MB per file. An Add-On
Pack for the Platform Builder 3.0 added even more features, including improved multimedia support
though a media player control; improved networking support (and XML support) with PPTP, ICS, and
remote desktop display support; and a formal introduction of the DirectX API.

The next release of Windows CE involved more than just new features; the name of the product was
also changed. Windows CE .NET 4.0, released in early 2001, changed the way virtual memory was
organized, effectively doubling the virtual memory space per application. Windows CE .NET 4.0 also
added a new driver loading model, services support, a new file-based registry option, Bluetooth,
802.11, and 1394 support. Ironically, while .NET was added to the name, Windows CE .NET 4.0
didn’t support the .NET Compact Framework.

Late in 2001, Windows CE 4.1 was a follow-on to Windows CE 4.0, adding IP v6, Winsock 2, a bunch
of new supporting applets, and an example Power Manager. Windows CE 4.1 also supports the .NET
Compact Framework. The final bits of the .NET runtime were released as a quick fix engineering
(QFE) package after the operating system shipped.

The second quarter of 2003 saw the release of Windows CE .NET 4.2. This update provided cool new
features for OEMs wanting to support Pocket PC applications on embedded systems. The Pocket
PC–specific APIs that support menu bars, the soft input panel (SIP), and other shell features were
moved to the base operating system. The Explorer shell was rewritten to support namespace
extensions. The performance of the kernel was improved by directly supporting hardware paging tables
on some CPUs.

Because Windows CE is a work in progress, the next version of Windows CE is being developed. I’ll
be updating my Web site, www.bolingconsulting.com, with information about this release as it
becomes available.
Why You Should Read This Book

Programming Microsoft Windows CE is written for anyone who will be writing applications for
Windows CE or the .NET Compact Framework. Embedded systems programmers using Windows CE
for a specific application, Windows programmers interested in writing or porting an existing Windows
application, and even developers of managed code can use the information in this book to make their
tasks easier.

The embedded systems programmer, who might not be as familiar with the Win32 API as the
Windows programmer, can read the first section of the book to become familiar with Windows
programming. Although this section isn’t the comprehensive tutorial that can be found in books such
as Programming Windows, by Charles Petzold, it does provide a base that will carry the reader through
the other chapters in the book. It can also help the embedded systems programmer develop fairly
complex and quite useful Windows CE programs.

The experienced Windows programmer can use the book to learn about the differences among the
Win32 APIs used by Windows CE and Windows XP. The differences between Windows CE and
Windows XP are significant. The small footprint of Windows CE means that many of the overlapping
APIs in the Win32 model aren’t supported. Some sections of the Win32 API aren’t supported at all. On
the other hand, because of its unique setting, Windows CE extends the Win32 API in a number of areas
that are covered in this text.

This book is also useful for the developer using the .NET Compact Framework. The Compact
Framework currently has gaps in its functionality: it requires managed applications to make calls to the
operating system to perform certain tasks. The book is a great guide to what’s available in the
operating system. A chapter in this book discusses the unique nature of developing managed code on
Windows CE–based devices.

The method used by Programming Windows CE is to teach by example. I wrote numerous Windows
CE example programs specifically for this book. The source for each of these examples is printed in
the text. Both the source and the final compiled programs for a number of the processors supported by
Windows CE are also provided on the accompanying CD.

The examples in this book are all written directly to the API, the so-called “Petzold” method of
programming. Since the goal of this book is to teach you how to write programs for Windows CE, the
examples avoid using a class library such as MFC, which obfuscates the unique nature of writing
applications for Windows CE. Some people would say that the availability of MFC on Windows CE
eliminates the need for direct knowledge of the Windows CE API. I believe the opposite is true.
Knowledge of the Windows CE API enables more efficient use of MFC. I also believe that truly
knowing the operating system also dramatically simplifies the debugging of applications.
What’s New in the Third Edition

The third edition of this book is a major revision that adds significant new text about a variety of
subjects from the Smartphone to Bluetooth. The book has been updated to cover the new features of
Windows CE .NET 4.2. New chapters have also been added to cover the Smartphone and the .NET
Compact Framework. A number of chapters have been significantly expanded to cover topics such as
OBEX, Bluetooth, and services. Other chapters have been reorganized to better present the topics.

A chapter has been added covering the Smartphone and the communication features of the Pocket PC
Phone Edition. This chapter covers how to write applications for the Smartphone 2003 device. Also
covered is how to write applications that work with the connection manager and send and receive
messages through the Short Message Service (SMS) system on both the Smartphone and the Pocket PC
Phone Edition.

There is a new chapter on the .NET Compact Framework. This chapter covers how to write managed
applications on Windows CE. After an introduction to managed applications, the chapter concentrates
on Windows Forms applications, the unique classes of the .NET Compact Framework. A significant
portion of the chapter covers how to call from managed code to unmanaged or native code since there
are times when the managed class library doesn’t provide the functionality necessary for the
application.

The device-to-device communication chapter contains coverage on Bluetooth and OBEX. Bluetooth is
a wireless communication standard that frankly isn’t well explained in many texts. This chapter
explains Bluetooth and provides a simple, straightforward example of its use. It also contains a section
on OBEX, the Object Exchange standard that’s used by both Bluetooth and Infrared Data Association
(IrDA). Another example in the chapter uses OBEX to send files to other devices over either Bluetooth
or IrDA.

The Pocket PC chapters have been updated to cover the new features of the Pocket PC 2003 devices.
The menu bar example from the Pocket PC chapter in the second edition of this book has been moved
to the common controls chapter, reflecting the move of the Pocket PC API to the general operating
system features in the latest version of Windows CE.

The drivers and services chapter has been updated to cover Windows CE services. Windows CE
services were introduced in Windows CE .NET 4.0. Services provide a way to have code running in
the background without the overhead of a separate process for the service. The operating system also
provides a super service that can monitor IP ports and notify a service when a client connects to that
port. A simple Windows CE service example is provided in the chapter, demonstrating how to write a
service and use the features of the super service.
For those owners of the first edition of this book, this edition contains all the new features of the
second edition as well. Those updates included extensive coverage of the Pocket PC and Windows CE
device drivers. Also, the new memory management and threading features that have been implemented
since the first edition was published make this edition a significant update.
.NET Compact Framework

A developer would have had to be on a desert island somewhere not to have heard of Microsoft’s .NET
initiative. This initiative consists of a run-time environment that isolates code from the hardware while
at the same time providing a type-safe runtime for increased security. A smaller version of this runtime
has been written for embedded and battery powered devices. The initial version of the .NET Compact
Framework runs on top of Windows CE on the Pocket PC and on embedded systems based on
Windows CE .NET 4.1 and later.

The unique requirements of embedded devices will make it a challenge to write applications using only
managed code. Embedded applications and some mobile applications require the application to be
tightly integrated with the device. Because one of the features of the runtime is to isolate the hardware
from the application, an embedded managed application sometimes needs to break the bounds of the
runtime and directly access some operating system functions.

As previously mentioned, the Compact Framework chapter spends a significant amount of time
discussing how managed applications can access the operating system. This discussion includes the
techniques for marshaling parameters across the managed/native code boundary—a task that’s
somewhat more difficult in the Compact Framework than on the desktop.
What About MFC?

I used to have a stock answer for people who asked me whether they should use MFC to build
Windows CE applications: Don’t do it! The old Windows CE systems with their slow CPUs were hard-
pressed to run complex, full-featured MFC applications. These days, I’m a little less dogmatic. The
newest Windows CE platforms are now fast enough to allow MFC-based applications to run with
reasonable performance. The MFC runtime library is included in ROM on these devices, so the
footprint of the application is simply the code, not the code plus the MFC runtime.

But just as speed and the runtime have been added to the platforms, the sun is setting on MFC.
Microsoft no longer pushes development of MFC applications. Instead, the .NET environment is the
development target of choice. So should you develop in MFC? I say no, not for new projects. For old
ones, there still is a place for MFC simply so that the projects don’t have to be ported to other tools.
Windows CE Development Tools

This book is written with the assumption that the reader knows C and is at least familiar with Microsoft
Windows. All native code development was done with Microsoft eMbedded Visual C++ under
Windows XP. To compile the example programs in this book, you need Microsoft eMbedded Visual
C++ 4.0, which is conveniently supplied on the companion CD. You also need the appropriate
platform SDKs for the Windows CE device you’re targeting.

Each example already has a predefined project set up, but you can also choose to create the projects
from scratch. For almost all the examples, simply create a generic WCE Application project. For the
examples that require access to functions unique to the Pocket PC, special code links to those
functions, even though the project settings don’t specifically define a Pocket PC application.

For developers who want to build applications that run on the Pocket PC 2000 and 2002, you need to
use Embedded Visual C++ 3.0. Unfortunately, there isn’t enough room on the companion CD for both
eVC 3 and eVC 4, but eVC 3 is available as a download from the Microsoft Web site. You’ll also need
the appropriate SDKs for those older Pocket PC systems. Many of the examples in the book can be
compiled for the older Pocket PC devices. Some examples, however, such as the Bluetooth, OBEX,
and services examples, use features that aren’t available on the older systems.

.NET Compact Framework applications are developed with Visual Studio .NET 2003. This tool isn’t
provided on the CD because it’s huge and, unfortunately for us programmers, not free. Still, this tool is
an incredibly productive development environment. For those interested in developing managed code,
the pain of the cost of upgrading is mitigated by the increase in developer productivity. You’ll need
Visual Studio .NET 2003 to compile the examples in the Compact Framework chapter. This tool
provides the necessary runtimes for all Pocket PC devices as well as embedded versions of Windows
CE based on version 4.1 or later.
Target Systems

You don’t need to have a Windows CE target device to experience the sample programs provided by
this book. The various platform SDKs come with a Windows CE emulator that lets you perform basic
testing of a Windows CE program under Windows XP. This emulator comes in handy when you don’t
have an actual device handy. The emulator runs a version of Windows CE inside a PC emulator which
results in an actual Windows CE operating system runtime executing on the PC.

You should consider a number of factors when deciding which Windows CE hardware to use for
testing. First, if the application is to be a commercial product, you should buy at least one system for
each type of target CPU. You need to test against all the target CPUs because, although the source
code will probably be identical, the resulting executable will be different in size and so will the
memory allocation footprint for each target CPU.
What’s on the CD

The companion CD contains the source code for all the examples in the book. I’ve also provided
project files for Microsoft eMbedded Visual C++ so that you can open preconfigured projects. All the
examples have been designed to compile for systems based on Windows CE 4.2, Pocket PC 2003, and
Smartphone 2003.

In addition to the examples, the CD also includes a free copy of Microsoft eMbedded Visual C++ 4.0.
This is the same full-featured eMbedded Visual C++ product that you can download from Microsoft’s
Web site or pay to have sent to you on CD. Consider these tools the prize in the Cracker Jack box. Also
included is the platform SDK for the Pocket PC 2003.

The companion CD contains a StartCD program that provides you with a graphical interface from
which you can access the contents of the CD. This program will autorun when the CD is inserted into
your CD-ROM drive if you have that feature enabled in Windows. If you don’t have autorun enabled,
just navigate to the root directory of the CD and run StartCD.exe from Windows Explorer. The file
Readme.txt, available from the StartCD program or in the root directory of the CD, will give you
additional information about the contents of the CD, system requirements for the included tools and
SDK, and information about support options for the included products.

The following are the system requirements for installing and running Microsoft eMbedded Visual C++.
Please note that to run the eMbedded Visual C++, you’ll need to be using Windows 2000, Windows
XP, or Windows Server 2003.

PC with Pentium processor; Pentium 150 MHz or higher processor recommended

Microsoft Windows XP, Windows 2000 Service Pack 2 (or later) or Windows Server 2003

32 MB of RAM (48 MB recommended)

Hard disk space required: minimum installation: about 360 MB; complete installation: about 720
MB

CD-ROM drive compatible with multimedia PC specification


VGA or higher-resolution monitor required; Super VGA recommended

Microsoft Mouse or compatible pointing device


Other Sources

Although I have attempted to make Programming Microsoft Windows CE a one-stop shop for
Windows CE programming, no one book can cover everything. To learn more about Windows
programming in general, I suggest the classic text Programming Windows (Microsoft Press, 1998) by
Charles Petzold. This is, by far, the best book for learning Windows programming. Charles presents
examples that show how to tackle difficult but common Windows problems. To learn more about the
Win32 kernel API, I suggest Jeff Richter’s Programming Applications for Microsoft Windows
(Microsoft Press, 1999). Jeff covers the techniques of process, thread, and memory management down
to the most minute detail. For learning more about MFC programming, there’s no better text than Jeff
Prosise’s Programming Windows with MFC (Microsoft Press, 1999). This book is the “Petzold” of
MFC programming and simply a required read for MFC programmers.

To learn more about .NET programming, I recommend Programming Windows with C# (Microsoft
Press, 2002), by Charles Petzold. Charles has applied his amazing skills to the Windows Forms part of
the .NET Framework. This is a great book to come up to speed on the client side of .NET
programming.
Support

Every effort has been made to ensure the accuracy of this book and the contents of the sample files on
the CD-ROM. Microsoft Press provides corrections and additional content for its books through the
World Wide Web at this location:

http://www.microsoft.com/mspress/support/

If you have problems, comments, or ideas regarding this book or the CD-ROM, please send them to
Microsoft Press.

Send e-mail to

[email protected]

Or send postal mail to

Microsoft Press

Attn: Programming Microsoft Windows CE, Third Edition, Editor

One Microsoft Way

Redmond, WA 98052-6399

Please note that product support is not offered through these mail addresses. For further information
regarding Microsoft software support options, please go to http://support.microsoft.com/directory/ or
call Microsoft Support Network Sales at (800) 936-3500.

Visit the Microsoft Press Web Site

You are also invited to visit the Microsoft Press World Wide Web site at the following location:

http://www.microsoft.com/mspress/

You’ll find descriptions for the complete line of Microsoft Press books, information about ordering
titles, notice of special features and events, additional content for Microsoft Press books, and much
more.
You can also find out the latest in Microsoft Windows CE .NET software developments and news from
Microsoft Corporation by visiting the following Web site:

http://www.microsoft.com/windows/embedded/ce.net/
Updates and Feedback

No book about Windows CE can be completely current for any length of time. I maintain a Web page,
http://www.bolingconsulting.com/cebook.htm, where I’ll keep a list of errata, along with updates
describing any features found in subsequent versions of Windows CE. Check out this page to see
information on new versions of Windows CE as they’re released.

Although I have striven to make the information in this book as accurate as possible, you’ll
undoubtedly find errors. If you find a problem with the text or just have ideas about how to make the
next version of the book better, please drop me a note at [email protected]. I can’t
promise you that I’ll answer all your notes, but I will read every one.

Doug Boling

Tahoe City, California

April 2003
Part I
Windows Programming Basics
Chapter 1
Hello Windows CE
Since the classic The C Programming Language, programming books traditionally start with a “hello,
world” program. It’s a logical place to begin. Every program has a basic underlying structure that,
when not obscured by some complex task it was designed to perform, can be analyzed to reveal the
foundation shared by all programs running on its operating system.

In this programming book, the “hello, world” chapter covers the details of setting up and using the
programming environment. The environment for developing Microsoft Windows CE applications is
somewhat different from that for developing standard Microsoft Windows applications because
Windows CE programs are written on PCs running Microsoft Windows XP and debugged mainly on
separate Windows CE–based target devices.

While experienced Windows programmers might be tempted to skip this chapter and move on to
meatier subjects, I suggest that they—you—at least skim the chapter to note the differences between a
standard Windows program and a Windows CE program. A number of subtle and significant
differences in both the development process and the basic program skeleton for Windows CE
applications are covered in this first chapter.
What Is Different About Windows CE

Windows CE has a number of unique characteristics that make it different from other Windows
platforms. First of all, the systems running Windows CE are most likely not using an Intel
x86–compatible microprocessor. Instead, Windows CE runs on 4 different CPU families, SHx, MIPS,
ARM, and x86. Fortunately, the development environment isolates the programmer from almost all of
the differences among the various CPUs.

Nor can a Windows CE program be assured of a screen or a keyboard. Pocket PC devices have a 240-
by-320-pixel portrait-style screen, while other systems might have screens with more traditional
landscape orientations in 480-by-240, 640-by-240, or 640-by-480-pixel resolution. An embedded
device might not have a display at all. The target devices might not support color. And, instead of a
mouse, most Windows CE devices have a touch screen. On a touch-screen device, left mouse button
clicks are achieved by means of a tap on the screen, but no obvious method exists for delivering right
mouse button clicks. To give you some method of delivering a right click, the Windows CE convention
is to hold down the Alt key while tapping. It’s up to the Windows CE application to interpret this
sequence as a right mouse click.

Fewer Resources in Windows CE Devices

The resources of the target devices vary radically across systems that run Windows CE. When writing
a standard Windows program, the programmer can make a number of assumptions about the target
device, almost always an IBM-compatible PC. The target device will have a hard disk for mass storage
and a virtual memory system that uses the hard disk as a swap device to emulate an almost unlimited
amount of (virtual) RAM. The programmer knows that the user has a keyboard, a two-button mouse,
and a monitor that these days almost assuredly supports 256 colors and a screen resolution of at least
800 by 600 pixels.

Windows CE programs run on devices that almost never have hard disks for mass storage. The absence
of a hard disk means more than just not having a place to store large files. Without a hard disk, virtual
RAM can’t be created by swapping data to the disk. So Windows CE programs are almost always run
in a low-memory environment. Memory allocations can, and often do, fail because of the lack of
resources. Windows CE might terminate a program automatically when free memory reaches a
critically low level. This RAM limitation has a surprisingly large impact on Windows CE programs
and is one of the main challenges involved in porting existing Windows applications to Windows CE.
Unicode

One characteristic that a programmer can count on when writing Windows CE applications is Unicode.
Unicode is a standard for representing a character as a 16-bit value as opposed to the ASCII standard
of encoding a character into a single 8-bit value. Unicode allows for fairly simple porting of programs
to different international markets because all the world’s known characters can be represented in one of
the 65,536 available Unicode values. Dealing with Unicode is relatively painless as long as you avoid
the dual assumptions made by most programmers that strings are represented in ASCII and that
characters are stored in single bytes.

A consequence of a program using Unicode is that with each character taking up two bytes instead of
one, strings are now twice as long. A programmer must be careful making assumptions about buffer
length and string length. No longer should you assume that a 260-byte buffer can hold 259 characters
and a terminating zero. Instead of the standard char data type, you should use the TCHAR data type.
TCHAR is defined to be char for Microsoft Windows 95 and Microsoft Windows 98 development and
unsigned short for Unicode-enabled applications for Microsoft Windows 2000, Windows XP, and
Windows CE development. These types of definitions allow source-level compatibility across ASCII-
and Unicode-based operating systems.

New Controls

Windows CE includes a number of new Windows controls designed for specific environments. New
controls include the command bar and menu bar controls that provide menu- and toolbar-like functions
all on one space-saving line, critical on the smaller screens of Windows CE devices. Other controls
have been enhanced for Windows CE. A version of the edit control in Windows CE can be set to
automatically capitalize the first letter of a word, great for the keyboardless design of a PDA. Windows
CE also supports most of the controls available on desktop versions of Windows. Some of these
controls are even more at home on Windows CE devices than on the desktop. For example, the date
and time picker control and calendar control assist calendar and organizer applications suitable for
handheld devices, such as the Handheld PC (H/PC) and the Pocket PC. Other standard Windows
controls have reduced function, reflecting the compact nature of Windows CE hardware-specific OS
configurations.

Componentization

Another aspect of Windows CE programming to be aware of is that Windows CE can be broken up and
reconfigured by Microsoft or by OEMs so that it can be better adapted to a target market or device.
Windows programmers usually just check the version of Windows to see whether it is from the
Microsoft Windows 95, 98, or Me line or Windows 2000, XP line; by knowing the version they can
determine what API functions are available to them. Windows CE, however, can be configured in
countless ways.

By far, the most popular configuration of Windows CE today is the Pocket PC. Microsoft defines the
specific set of Windows CE components that are present in all Pocket PC–branded devices. However,
some OEMs produce PDA devices that use Windows CE but are not branded as Pocket PCs. These
devices have a subtly different API from that of the Pocket PC devices. If you are unaware of this, you
can easily write a program that works on one platform but not on another. In embedded platforms, the
OEM decides the components to include and can create a Software Development Kit (an SDK)
specialized for its specific platform. If the OEM is interested in third-party development, it can make
available a customized SDK for its device. New platforms are continually being released, with much in
common but also with many differences among them. Programmers need to understand the target
platform and to have their programs check what functions are available on that particular platform
before trying to use a set of functions that might not be supported on that device.

Win32 Subset

Finally, because Windows CE is so much smaller than Windows XP, it simply can’t support all the
function calls that its larger cousins do. While you’d expect an operating system that didn’t support
printing, such as Windows CE on the original models, not to have any calls to printing functions,
Windows CE also removes some redundant functions supported by its larger cousins. If Windows CE
doesn’t support your favorite function, a different function or set of functions will probably work just
as well. Sometimes Windows CE programming seems to consist mainly of figuring out ways to
implement a feature using the sparse API of Windows CE. If thousands of functions can be called
sparse.
It’s Still Windows Programming

While differences between Windows CE and the other versions of Windows do exist, they shouldn’t be
overstated. Programming a Windows CE application is programming a Windows application. It has the
same message loop, the same windows, and for the most part, the same resources and the same
controls. The differences don’t hide the similarities. One of the key similarities is the tradition of
Hungarian notation.

Hungarian Notation

A tradition, and a good one, of almost all Windows programs since Charles Petzold wrote
Programming Microsoft Windows is Hungarian notation. This programming style, developed years ago
by Charles Simonyi at Microsoft, prefixes all variables in the program usually with one or two letters
indicating the variable type. For example, a string array named Name would instead be named szName,
with the sz prefix indicating that the variable type is a zero-terminated string. The value of Hungarian
notation is the dramatic improvement in readability of the source code. Another programmer, or you
after not looking at a piece of code for a while, won’t have to look repeatedly at a variable’s
declaration to determine its type. Table 1-1 shows typical Hungarian prefixes for variables.

Table 1-1. Hungarian Prefixes for Variables


Variable Type Hungarian Prefix

Integer i or n

Word (16-bit) w or s

Double word (32-bit unsigned) Dw


Long (32-bit signed) L
Char C

String Sz
Pointer P
Long pointer lp
Variable Type Hungarian Prefix

Handle h

Window handle hwnd

Struct size cb

You can see a few vestiges of the early days of Windows. The lp, or long pointer, designation refers to
the days when, in the Intel 16-bit programming model, pointers were either short (a 16-bit offset) or
long (a segment plus an offset). Other prefixes are formed from the abbreviation of the type. For
example, a handle to a brush is typically specified as hbr. Prefixes can be combined, as in lpsz, which
designates a long pointer to a zero-terminated string. Most of the structures defined in the Windows
API use Hungarian notation in their field names. I use this notation as well throughout this book, and I
encourage you to use this notation in your programs.
Your First Windows CE Application

Enough talk; let’s look at your first Windows CE program. Listing 1-1 shows Hello1, a simple Hello
World application written for Windows CE.

Listing 1-1. Hello1, A simple Windows application

Hello1.cpp
//======================================================================
// Hello1 - A simple application for Windows CE
//
// Written for the book Programming Windows CE
// Copyright (C) 2003 Douglas Boling
//======================================================================
#include "windows.h"

//
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {

printf ("Hello World\n");


return 0;
}

As you can see, aside from the entry point of the program, the code looks fairly similar to the classic
Kernighan and Ritchie version. Starting from just below the comments, we have the line

#include "windows.h"

which is the root of a vast array of include files that define the Windows CE API, as well as the
structures and constants they use.

The entry point of the program is the biggest difference between this program and a standard C
program. Instead of the C standard

int main (char **argv, int argc)


the Windows CE build environment expects the standard Windows entry point, While it is technically
possible to change the entry point prototype to match the C standard entry point, it typically isn’t worth
the trouble. as in

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,


LPWSTR lpCmdLine, int nCmdShow);

Windows CE differs in some ways from the desktop versions of Windows. The first of the four
parameters passed, hInstance, identifies the specific instance of the program to other applications and
to Windows API functions that need to identify the EXE. The hPrevInstance parameter is left over
from the old Win16 API (Windows 3.1 and earlier). In all Win32 operating systems, including
Windows CE, hPrevInstance is always 0 and can be ignored.

The lpCmdLine parameter points to a Unicode string that contains the text of the command line.
Applications launched from Microsoft Windows Explorer usually have no command-line parameters.
But in some instances, such as when the system automatically launches a program, the system includes
a command-line parameter to indicate why the program was started. The lpCmdLine parameter
provides us with one of the first instances in which Windows CE differs from Windows XP. Under
Windows CE, the command-line string is a Unicode string. In all other versions of Windows, the string
is always ASCII.

The final parameter, nCmdShow, specifies the initial state of the program’s main window. It is passed
by the parent application, usually Explorer, and is a recommendation of how the application should
configure its main window. This parameter might specify that the window be initially displayed as an
icon (SW_SHOWMINIMIZE), maximized (SW_SHOWMAXIMIZED) to cover the entire desktop, or
normal (SW_RESTORE), indicating that the window is placed on the screen in the standard resizeable
state. Other values specify that the initial state of the window should be invisible to the user or that the
window should be visible but incapable of becoming the active window. Under Windows CE, the
values for this parameter are limited to only three allowable states: normal (SW_SHOW), hidden
(SW_HIDE), and show without activate (SW_SHOWNOACTIVATE). Unless an application needs to
force its window to a predefined state, this parameter is simply passed without modification to the
ShowWindow function after the program’s main window has been created.

The next line is the only functioning line of the application.

printf ("Hello World\n");

Windows CE supports most of the standard C library, including printf, getchar, and so forth. An
interesting aspect of this line is that unlike almost everywhere else in Windows CE, the string is not
Unicode but ANSI. There is a logical reason for this. For the C standard library to be compliant with
the ANSI standard, printf and the other string library functions such as strcpy use ANSI strings. Of
course, Windows CE supports the Unicode versions of the standard functions such as wprintf,
getwchar, and wcscpy.
Finally the program ends with

return 0;

The value passed in the return line is available to other processes that use the Win32 API
GetExitCodeProcess.

Building Your First Application

To create Hello1 from scratch on your system, start Microsoft eMbedded Visual C++ and create a new
project by selecting the New command on the File menu. The first change from standard Win32
programming becomes evident when you see the new project dialog box. You’ll have the opportunity
to select from a number of platforms, as shown in Figure 1-1. For non-MFC or ATL projects, the chief
decision is to choose between WCE Pocket PC Application (to build code for a Pocket PC) and WCE
Application (for all other Windows CE systems). You’ll also pick the allowable target CPUs. For
example, selecting Win32 (WCE MIPII) enables compiling to a Windows CE platform with a MIPS
CPU. No matter what target device you have, be sure to check the WCE emulator target. This allows
you to run the sample program in the emulator under Windows XP.

Figure 1-1. The Platforms list box allows eMbedded Visual C++ to target different Windows CE
platforms

eMbedded Visual C++ will next ask you whether you want to create an empty project, a simple
program, or a Hello World application. For all the examples in this book, pick Empty Project. This
choice prevents the code wizards from adding any extra code to the examples. Create new files for
Hello1.cpp from the File menu by clicking New.

After you have created the proper source files for Hello1 or copied them from the CD, select the target
Win32 (WCE x86em) Debug and then build the program. This step compiles the source and, assuming
you have no compilation errors, automatically launches the emulator and inserts the EXE into the
emulator file system; you can then launch Hello1. If you’re running Windows 98 or Windows Me, the
system displays an error message because the emulator runs only under Windows 2000 or Windows
XP.

If you have a Windows CE system available, such as a Pocket PC (PPC), attach the PPC to the PC the
same way you would to sync the contents of the PPC with the PC. Open Microsoft ActiveSync, and
establish a connection between the PPC and the PC. While it’s not strictly necessary to have the
ActiveSync connection to your Windows CE device running (eMbedded Visual C++ is supposed to
make this connection automatically), I’ve found that having it running makes for a more stable
connection between the development environment and the Windows CE system.

Once the link between the PC and the Windows CE device is up and running, switch back to
eMbedded Visual C++, select the compile target appropriate for the target device (for example, Win32
[WCE ARM] Debug for an iPaq Pocket PC), and rebuild. As in the case of building for the emulator, if
there are no errors, eMbedded Visual C++ automatically downloads the compiled program to the
remote device. The program is placed either in the root directory of the object store or, in the case of
the Pocket PC, in the \windows\start menu directory.

Running the Program

To run Hello1 on an embedded Windows CE deviceH/PC, simply click on the My ComputerHandheld


PC icon to bring up the files in the root directory. At that point, a double-tap on the application’s icon
launches the program.

To run the program on a Pocket PC, simply select the program from the Start menu on the device. The
program appears there because eMbedded Visual C++ downloads the application to be the
\windows\start menu directory. This way, a downloaded application is automatically visible on the
Start menu.

What’s Wrong?
If you start Hello1 by clicking on the icon or by selecting the program on the start menu of a Pocket
PC, nothing seems to happen. On a Handheld PC, the program appears to make the screen flash. This is
because the program starts, writes to the console, and terminates. Unless you start the program from an
already created console, Windows CE creates the console window when Hello1 executes the printf
statement and closes the console automatically when Hello1 terminates.

On a Pocket PC, the application runs, but the Pocket PC doesn’t come with support to display the
console functions such as the output from printf. It’s possible to add console support to a Pocket PC by
adding a driver, console.dll, to the Windows directory of the Pocket PC. That driver must be written to
take input from the driver interface, create a window on the screen, and print out the strings. The
console driver available on Handheld PCs and in embedded versions of Windows CE does this.
Hello2

Now that we have the basics down, it’s time to upgrade Hello1 to something you can at least see.
Because many Windows CE systems don’t have the console driver, Hello2 creates a message box with
the “Hello CE” text instead of using printf. Hello2 is shown in Listing 1-2.

Listing 1-2. Hello2, a simple Windows application using the MessageBox function

Hello2.cpp
//======================================================================
// Hello2 - A simple application for Windows CE
//
// Written for the book Programming Windows CE
// Copyright (C) 2003 Douglas Boling
//======================================================================
#include "windows.h"

//
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {

MessageBox (NULL, TEXT ("Hello World"), TEXT ("Hello2"), MB_OK);


return 0;
}

When you compile and run Hello2, you should see a small window like the one shown in Figure 1-2.
Figure 1-2. Hello2 running on a Windows CE desktop

The MessageBox function that replaces printf provides two features for Hello2. First and most obvious,
it creates a window and places the “Hello World” text in the window. The second feature is that the
MessageBox function doesn’t return until the user closes the message box window. This feature allows
Hello2 to keep running until the user dismisses the window.

The MessageBox function is prototyped as

int MessageBox (HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);

The first parameter of MessageBox is the handle to the top-level window that will be the parent of the
message box when it is displayed. For now, we can leave this parameter NULL because Hello2 doesn’t
have any other windows. The second parameter is the text that appears in the window. Notice that the
string passed is couched in the TEXT macro, ensuring that it will be compiled as Unicode. The third
parameter, lpCaption, is the text that will appear in the title bar of the window. The last parameter,
uType, is a series of flags that specify how the message box appears on the screen. The flags specify
the number and type of buttons on the message box; the icon, if any, on the message box; and the
settings of style flags for the message box window.

The flags listed in Table 1-2 are valid under Windows CE.

Table 1-2. Default Flags


Flags Button or Icon

For Buttons:
MB_OK OK
MB_OKCANCEL OK and Cancel

MB_RETRYCANCEL Retry and Cancel


Flags Button or Icon

MB_YESNO Yes and No

MB_YESNOCANCEL Yes, No, and Cancel

MB_ABORTRETRYIGNORE Abort, Retry, and Ignore


For Icons:

MB_ICONEXCLAMATION, MB_ICONWARNING Exclamation point


MB_ICONINFORMATION, MB_ICONASTERISK Lower case i within a circle
MB_ICONQUESTION Question mark

MB_YESNO Yes and No

MB_ICONSTOP, MB_ICONERROR, Stop sign


MB_ICONHAND

MB_DEFBUTTON1 First button

MB_DEFBUTTON2 Second button


MB_DEFBUTTON3 Third button

For Window Styles:

MB_SETFOREGROUND Bring the message box to the foreground.


MB_TOPMOST Make the message box the topmost
window.

The return value from MessageBox indicates the button pressed by the user. The return values are as
follows:

IDOK OK button pressed


IDYES Yes button pressed
IDNO No button pressed

IDCANCEL Cancel button pressed or Esc key pressed


IDABORT Abort button pressed
IDOK OK button pressed

IDRETRY Retry button pressed

IDIGNORE Ignore button pressed

MessageBox is a handy function to have an application display a simple but informative dialog box.

One gotcha to look out for here: If you’re debugging and recompiling the program, it can’t be
downloaded again if an earlier version of the program is still running on the target system. That is,
make sure Hello2 isn’t running on the remote system when you start a new build in eMbedded Visual
C++, or the autodownload part of the compile process will fail. If this happens, close the application
and choose the Update Remote File menu command in eMbedded Visual C++ to download the newly
compiled file.

Hello2 displays a simple window, but that window is only as configurable as the MessageBox function
allows. How about showing a window that is completely configurable by the application? Before we
can do that, a quick review of how a Windows application really works is in order.
Anatomy of a Windows-Based Application

Windows-based programming is far different from MS-DOS–based or Unix-based programming. An


MS-DOS or Unix program uses getc- and putc-style functions to read characters from the keyboard
and write them to the screen whenever the program needs to do so. This is the classic “pull” style used
by MS-DOS and Unix programs, which are procedural. A Windows program, on the other hand, uses a
“push” model, in which the program must be written to react to notifications from the operating system
that a key has been pressed or a command has been received to repaint the screen.

Windows applications don’t ask for input from the operating system; the operating system notifies the
application that input has occurred. The operating system achieves these notifications by sending
messages to an application window. All windows are specific instances of a window class. Before we
go any further, let’s be sure we understand these terms.

The Window Class

A window is a region on the screen, rectangular in all but the most contrived of cases, that has a few
basic parameters, such as position—x, y, and z (a window is over or under other windows on the
screen)—visibility, and hierarchy—the window fits into a parent/child window relationship on the
system desktop, which also happens to be a window.

Every window created is a specific instance of a window class. A window class is a template that
defines a number of attributes common to all the windows of that class. In other words, windows of the
same class have the same attributes. The most important of the shared attributes is the window
procedure.

The Window Procedure

The behavior of all windows belonging to a class is defined by the code in its window procedure for
that class. The window procedure handles all notifications and requests sent to the window. These
notifications are sent either by the operating system, indicating that an event has occurred to which the
window must respond, or by other windows querying the window for information.

These notifications are sent in the form of messages. A message is nothing more than a call being made
to a window procedure, with a parameter indicating the nature of the notification or request. Messages
are sent for events such as a window being moved or resized or to indicate a key press. The values used
to indicate messages are defined by Windows. Applications use predefined constants, such as
WM_CREATE and WM_MOVE, when referring to messages. Since hundreds of messages can be sent,
Windows conveniently provides a default processing function to which a message can be passed when
no special processing is necessary by the window class for that message.

The Life of a Message

Stepping back for a moment, let’s look at how Windows coordinates all of the messages going to all of
the windows in a system. Windows monitors all the sources of input to the system, such as the
keyboard, mouse, touch screen, and any other hardware that could produce an event that might interest
a window. As an event occurs, a message is composed and directed to a specific window. Instead of
Windows directly calling the window procedure, the system imposes an intermediate step. The
message is placed in a message queue for the application that owns the window. When the application
is prepared to receive the message, it pulls it out of the queue and tells Windows to dispatch that
message to the proper window in the application.

If it seems to you that a number of indirections are involved in that process, you’re right. Let’s break it
down.

1. An event occurs, so a message is composed by Windows and placed in a message queue for the
application that owns the destination window. In Windows CE, as in Windows XP, each application
has its own unique message queue. Technically, each thread in a Windows CE application can have
a message queue. I’ll talk about threads later in the book. (This is a break from Windows 3.1 and
earlier versions of Windows, where there was only one, systemwide, message queue.) Events can
occur, and therefore messages can be composed, faster than an application can process them. The
queue allows an application to process messages at its own rate, although the application had better
be responsive or the user will see a jerkiness in the application. The message queue also allows
Windows to set a notification in motion and continue with other tasks without having to be limited
by the responsiveness of the application to which the message is being sent.

2. The application removes the message from its message queue and calls Windows back to dispatch
the message. While it may seem strange that the application gets a message from the queue and then
simply calls Windows back to process the message, there’s a method to this madness. Having the
application pull the message from the queue allows it to preprocess the message before it asks
Windows to dispatch the message to the appropriate window. In a number of cases, the application
might call different functions in Windows to process specific kinds of messages.

3. Windows dispatches the message; that is, it calls the appropriate window procedure. Instead of
3.
having the application directly call the window procedure, another level of indirection occurs,
allowing Windows to coordinate the call to the window procedure with other events in the system.
The message doesn’t stand in another queue at this point, but Windows might need to make some
preparations before calling the window procedure. In any case, the scheme relieves the application
of the obligation to determine the proper destination window—Windows does this instead.

4. The window procedure processes the message. All window procedures have the same calling
parameters: the handle of the specific window instance being called, the message, and two generic
parameters that contain data specific to each message type. The window handle differentiates each
instance of a window for the window procedure. The message parameter, of course, indicates the
event that the window must react to. The two generic parameters contain data specific to the
message being sent. For example, in a WM_MOVE message indicating that the window is about to
be moved, one of the generic parameters points to a structure containing the new coordinates of the
window.
Hello3

Enough review. It’s time to jump into a full-fledged Windows application, Hello3. While the entire
program files for this and all examples in the book are available in the companion CD-ROM, I suggest
that, as in the earlier example, you avoid simply loading the project file from the CD and instead type
in the entire example by hand. By performing this somewhat tedious task, you’ll see the differences in
the development process as well as the subtle program differences between standard Win32 programs
and Windows CE programs. Listing 1-3 contains the complete source code for Hello3.

Listing 1-3. The Hello3 program

Hello3.cpp
//======================================================================
// Hello3 - A simple application for Windows CE
//
// Written for the book Programming Windows CE
// Copyright (C) 2003 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff

LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

//======================================================================
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
WNDCLASS wc;
HWND hWnd;
MSG msg;

// Register application main window class.


wc.style = 0; // Window style
wc.lpfnWndProc = MainWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = 0; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
Random documents with unrelated
content Scribd suggests to you:
extend the system over a long period of years, make it normal to
industry and accepted as a habit in men’s daily conception of the
way in which their lives should be conducted, and the method is
necessarily transformed into a system of compulsory labour. In
trades where wages fluctuate little this will obviously be the case.
“You, the agricultural labourers of this district, have taken fifteen
shillings a week for a very long time. It has worked perfectly well.
There seems no reason why you should have more. Nay, you put
your hands to it through your officials in the year so and so that you
regarded that sum as sufficient. Such and such of your members are
now refusing to perform what this Court regards as a contract. They
must return within the limits of that contract or suffer the
consequences.”

Remember what power analogy exercises over men’s minds, and


how, when systems of the sort are common to many trades, they
will tend to create a general point of view for all trades. Remember
also how comparatively slight a threat is already sufficient to control
men in our industrial society, the proletarian mass of which is
accustomed to live from week to week under peril of discharge, and
has grown readily amenable to the threat of any reduction in those
wages upon which it can but just subsist.

Nor are the Courts enforcing such contracts or quasi-contracts (as


they will come to be regarded) the only inducement.

A man has been compelled by law to put aside sums from his wages
as insurance against unemployment. But he is no longer the judge of
how such sums shall be used. They are not in his possession; they
are not even in the hands of some society which he can really
control. They are in the hands of a Government official. “Here is
work offered you at twenty-five shillings a week. If you do not take it
you certainly shall not have a right to the money you have been
compelled to put aside. If you will take it the sum shall still stand to
your credit, and when next in my judgment your unemployment is
not due to your recalcitrance and refusal to labour, I will permit you
to have some of your money: not otherwise.” Dovetailing in with this
machinery of compulsion is all that mass of registration and
docketing which is accumulating through the use of Labour
Exchanges. Not only will the Official have the power to enforce
special contracts, or the power to coerce individual men to labour
under the threat of a fine, but he will also have a series of dossiers
by which the record of each workman can be established. No man,
once so registered and known, can escape; and, of the nature of the
system, the numbers caught in the net must steadily increase until
the whole mass of labour is mapped out and controlled.

These are very powerful instruments of compulsion indeed. They


already exist. They are already a part of our laws.

Lastly, there is the obvious bludgeon of “compulsory arbitration”: a


bludgeon so obvious that it is revolting even to our proletariat.
Indeed, I know of no civilised European state which has succumbed
to so gross a suggestion. For it is a frank admission of servitude at
one step, and for good and all, such as men of our culture are not
yet prepared to swallow. 11

So much, then, for the first argument and the first form in which
compulsory labour is seen to be a direct and necessary consequence
of establishing a minimum wage and of scheduling employment to a
scale.

The second is equally clear. In the production of wheat the healthy


and skilled man who can produce ten measures of wheat is
compelled to work for six measures, and the Capitalist is compelled
to remain content with four measures for his share. The law will
punish him if he tries to get out of his legal obligation and to pay his
workmen less than six measures of wheat during the year. What of
the man who is not sufficiently strong or skilled to produce even six
measures? Will the Capitalist be constrained to pay him more than
the values he can produce? Most certainly not. The whole structure
of production as it was erected during the Capitalist phase of our
industry has been left intact by the new laws and customs. Profit is
still left a necessity. If it were destroyed, still more if a loss were
imposed by law, that would be a contradiction of the whole spirit in
which all these reforms are being undertaken. They are being
undertaken with the object of establishing stability where there is
now instability, and of “reconciling,” as the ironic phrase goes, “the
interests of capital and labour.” It would be impossible, without a
general ruin, to compel capital to lose upon the man who is not
worth even the minimum wage. How shall that element of insecurity
and instability be eliminated? To support the man gratuitously
because he cannot earn a minimum wage, when all the rest of the
commonwealth is working for its guaranteed wages, is to put a
premium upon incapacity and sloth. The man must be made to
work. He must be taught, if possible, to produce those economic
values, which are regarded as the minimum of sufficiency. He must
be kept at that work even if he cannot produce the minimum, lest
his presence as a free labourer should imperil the whole scheme of
the minimum wage, and introduce at the same time a continuous
element of instability. Hence he is necessarily a subject for forced
labour. We have not yet in this country, established by force of law,
the right to this form of compulsion, but it is an inevitable
consequence of those other reforms which have just been reviewed.
The “Labour Colony” (a prison so called because euphemism is
necessary to every transition) will be erected to absorb this surplus,
and that last form of compulsion will crown the edifice of these
reforms. They will then be complete so far as the subject classes are
concerned, and even though this particular institution of the “Labour
Colony” (logically the last of all) precede in time other forms of
compulsion, it will make the advent of those other forms of
compulsion more certain, facile, and rapid.
There remains one last remark to be made upon the concrete side of
my subject. I have in this last section illustrated the tendency
towards the Servile State from actual laws and actual projects with
which all are to-day familiar in English industrial society, and I have
shown how these are certainly establishing the proletariat in a novel,
but to them satisfactory, Servile Status.

It remains to point out in a very few lines the complementary truth


that what should be the very essence of Collectivist Reform, to wit,
the translation of the means of production from the hands of private
owners to the hands of public officials, is nowhere being attempted.
So far from its being attempted, all so-called “Socialistic”
experiments in municipalisation and nationalisation are merely
increasing the dependence of the community upon the Capitalist
class. To prove this, we need only observe that every single one of
these experiments is effected by a loan.

Now what is meant in economic reality by these municipal loans and


national loans raised for the purpose of purchasing certain small
sections of the means of production?

Certain Capitalists own a number of rails, cars, etc. They put to work
upon these certain Proletarians, and the result is a certain total of
economic values. Let the surplus values obtainable by the Capitalists
after the subsistence of the proletarians is provided for amount to
£10,000 a year. We all know how a system of this sort is
“Municipalised.” A “loan” is raised. It bears “interest.” It is saddled
with a “sinking fund.”

Now this loan is not really made in money, though the terms of it are
in money. It is, at the end of a long string of exchanges, nothing
more nor less than the loan of the cars, the rails, etc., by the
Capitalists to the Municipality. And the Capitalists require, before
they will strike the bargain, a guarantee that the whole of their old
profit shall be paid to them, together with a further yearly sum,
which after a certain number of years shall represent the original
value of the concern when they handed it over. These last additional
sums are called the “sinking fund”; the continued payment of the old
surplus values is called the “interest.”

In theory certain small sections of the means of production might be


acquired in this way. That particular section would have been
“socialised.” The “Sinking Fund” (that is, the paying of the Capitalists
for their plant by instalments) might be met out of the general
taxation imposed on the community, considering how large that is
compared with any one experiment of the kind. The “interest” may
by good management be met out of the true profits of the
tramways. At the end of a certain number of years the community
will be in possession of the tramways, will no longer be exploited in
this particular by Capitalism, will have bought out Capitalism from
the general taxes, and, in so far as the purchase money paid has
been consumed and not saved or invested by the Capitalists, a small
measure of “socialisation” will have been achieved.

As a fact things are never so favourable.

In practice three conditions militate against even these tiny


experiments in expropriation: the fact that the implements are
always sold at much more than their true value; the fact that the
purchase includes non-productive things; and the fact that the rate
of borrowing is much faster than the rate of repayment. These three
adverse conditions lead in practice to nothing but the riveting of
Capitalism more securely round the body of the State.

For what is it that is paid for when a tramway, for instance, is taken
over? Is it the true capital alone, the actual plant, which is paid for,
even at an exaggerated price? Far from it! Over and above the rails
and the cars, there are all the commissions that have been made, all
the champagne luncheons, all the lawyers’ fees, all the
compensations to this man and to that man, all the bribes. Nor does
this exhaust the argument. Tramways represent a productive
investment. What about pleasure gardens, wash-houses, baths,
libraries, monuments, and the rest? The greater part of these things
are the product of “loans.” When you put up a public institution you
borrow the bricks and the mortar and the iron and the wood and the
tiles from Capitalists, and you pledge yourself to pay interest, and to
produce a sinking fund precisely as though a town hall or a bath
were a piece of reproductive machinery.

To this must be added the fact that a considerable proportion of the


purchases are failures: purchases of things just before they are
driven out by some new invention; while on the top of the whole
business you have the fact that the borrowing goes on at a far
greater rate than the repayment.

In a word, all these experiments up and down Europe during our


generation, municipal and national, have resulted in an indebtedness
to capital increasing rather more than twice, but not three times, as
fast as the rate of repayment. The interest which capital demands
with a complete indifference as to whether the loan is productive or
non-productive amounts to rather more than 1½ per cent. excess
over the produce of the various experiments, even though we count
in the most lucrative and successful of these, such as the state
railways of many countries, and the thoroughly successful municipal
enterprises of many modern towns.

Capitalism has seen to it that it shall be a winner and not a loser by


this form of sham Socialism, as by every other. And the same forces
which in practice forbid confiscation see to it that the attempt to
mask confiscation by purchase shall not only fail, but shall turn
against those who have not had the courage to make a frontal
attack upon privilege.

With these concrete examples showing how Collectivism, in


attempting its practice, does but confirm the Capitalist position, and
showing how our laws have already begun to impose a Servile
Status upon the Proletariat, I end the argumentative thesis of this
book.

I believe I have proved my case.

The future of industrial society, and in particular of English society,


left to its own direction, is a future in which subsistence and security
shall be guaranteed for the Proletariat, but shall be guaranteed at
the expense of the old political freedom and by the establishment of
that Proletariat in a status really, though not nominally, servile. At
the same time, the Owners will be guaranteed in their profits, the
whole machinery of production in the smoothness of its working,
and that stability which has been lost under the Capitalist phase of
society will be found once more.

The internal strains which have threatened society during its


Capitalist phase will be relaxed and eliminated, and the community
will settle down upon that Servile basis which was its foundation
before the advent of the Christian faith, from which that faith slowly
weaned it, and to which in the decay of that faith it naturally
returns.
Conclusion
It is possible to portray a great social movement of the past with
accuracy and in detail if one can spare to the task the time
necessary for research and further bring to it a certain power of co-
ordination by which a great mass of detail can be integrated and
made one whole.

Such a task is rarely accomplished, but it does not exceed the


powers of history.

With regard to the future it is otherwise. No one can say even in its
largest aspect or upon its chief structural line what that future will
be. He can only present the main tendencies of his time: he can only
determine the equation of the curve and presume that that equation
will apply more or less to its next developments.

So far as I can judge, those societies which broke with the continuity
of Christian civilisation in the sixteenth century—which means,
roughly, North Germany and Great Britain—tend at present to the re-
establishment of a Servile Status. It will be diversified by local
accident, modified by local character, hidden under many forms. But
it will come.

That the mere Capitalist anarchy cannot endure is patent to all men.
That only a very few possible solutions to it exist should be equally
patent to all. For my part, as I have said in these pages, I do not
believe there are more than two: a reaction towards well-divided
property, or the re-establishment of servitude. I cannot believe that
theoretical Collectivism, now so plainly failing, will ever inform a real
and living society.
But my conviction that the re-establishment of the Servile Status in
industrial society is actually upon us does not lead me to any meagre
and mechanical prophecy of what the future of Europe shall be. The
force of which I have been speaking is not the only force in the field.
There is a complex knot of forces underlying any nation once
Christian; a smouldering of the old fires.

Moreover, one can point to European societies which will most


certainly reject any such solution of our Capitalist problem, just as
the same societies have either rejected, or lived suspicious of,
Capitalism itself, and have rejected or lived suspicious of that
industrial organisation which till lately identified itself with “progress”
and national well-being.

These societies are in the main the same as those which, in that
great storm of the sixteenth century,—the capital episode in the
story of Christendom—held fast to tradition and saved the continuity
of morals. Chief among them should be noted to-day the French and
the Irish.

I would record it as an impression and no more that the Servile


State, strong as the tide is making for it in Prussia and in England to-
day, will be modified, checked, perhaps defeated in war, certainly
halted in its attempt to establish itself completely, by the strong
reaction which these freer societies upon its flank will perpetually
exercise.

Ireland has decided for a free peasantry, and our generation has
seen the solid foundation of that institution laid. In France the many
experiments which elsewhere have successfully introduced the
Servile State have been contemptuously rejected by the populace,
and (most significant!) a recent attempt to register and to “insure”
the artisans as a separate category of citizens has broken down in
the face of an universal and a virile contempt.
That this second factor in the development of the future, the
presence of free societies, will destroy the tendency to the Servile
State elsewhere I do not affirm, but I believe that it will modify that
tendency, certainly by example and perhaps by direct attack. And as
I am upon the whole hopeful that the Faith will recover its intimate
and guiding place in the heart of Europe, so I believe that this
sinking back into our original Paganism (for the tendency to the
Servile State is nothing less) will in due time be halted and reversed.

Videat Deus.
Endnotes
1. Save in this special sense of “Collectivist,” the word “Socialist”
has either no clear meaning, or is used synonymously with other
older and better-known words. ↩

2. The purchasing power of money fell during this century to about


a third of its original standard. £3 (say) would purchase under
Charles I the necessities which £1 would have purchased under
Henry VIII. Nearly all the receipts of the Crown were customary.
Most of its expenses were competitive. It continued to get but
£1 where it was gradually compelled to pay out £3. ↩

3. Before any trust is established in this country, the first step is to


“interest” one of our politicians. The Telephones, the South
Wales Coal Trust, the happily defeated Soap Trust, the Soda,
Fish, and Fruit Trusts, are examples in point. ↩

4. By which word “property” is meant, of course, property in the


means of Production. ↩

5. That this is an illusion I shall attempt to show on a later page.


6. By an illusion which clever statesmanship could use to the


advantage of the community, he even estimates the natural
forces he controls (which need no accumulation, but are always
present) on the analogy of his capital, and will part with them at
“so many years’ purchase.” It is by taking advantage of this
illusion that land purchase schemes (as in Ireland) happily work
to the advantage of the dispossessed. ↩
7. Thus you can raid the brewers in a society half-Puritan where
brewing is thought immoral by many, but proceed to railway
stock and it will be a very different matter. ↩

8. In using this metaphor I at once record my apologies to those


who believe in elliptical and hyperbolic universes, and confess
myself an old-fashioned parabolist. Further, I admit that the
triangles in question are spherical. ↩

9. Thus the money levied upon the death of some not very
wealthy squire and represented by, say, locomotives in the
Argentine, turns into two miles of palings for the pleasant back
gardens of a thousand new officials under the Inebriates Bill, or
is simply handed over to the shareholders of the Prudential
under the Insurance Act. In the first case the locomotives have
been given back to the Argentine, and after a long series of
exchanges have been bartered against a great number of wood-
palings from the Baltic not exactly reproductive wealth. In the
second case the locomotives which used to be the squire’s
hands become, or their equivalent becomes, means of
production in the hands of the Sassoons. ↩

10. How true it is that the idea of status underlies this legislation
can easily be tested by taking parallel cases, in one of which
working men are concerned, in the other the professional class.
If I contract to write for a publisher a complete History of the
County of Rutland, and in the pursuit of that task, while
examining some object of historical interest, fall down a pit, I
should not be able to recover against the publisher. But if I
dress in mean clothes, and the same publisher, deceived, gives
me a month’s work at cleaning out his ornamental water and I
am wounded in that occupation by a fierce fish, he will be
mulcted to my advantage, and that roundly. ↩

11. But it has twice been brought forward in due process as a Bill in
Parliament! ↩
*** END OF THE PROJECT GUTENBERG EBOOK THE SERVILE
STATE ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookgate.com

You might also like