`
`by
`
`icrosoft
`
`Windows
`
`Ill
`
`fl
`
`Douglas BoUng
`
`Samsung Exhibit 1032 Page 00001
`
`
`
`~
`'(!!9/
`
`Microsoft•
`WindO\V?CE
`
`,..
`
`\
`
`QA76. 76
`063
`Bo23
`1998
`
`Boling
`
`Microsoft
`- - - -
`PRESS
`
`;
`
`Page 00002
`
`
`
`PL
`
`AQrOr t\JYJtsj
`cp fl-1L
`
`NORTH
`
`CAROLINA
`
`STATE UNIVERSITY LIBRARIES
`
`S01237722
`
`Page 00003
`
`
`
`GRA
`
`I 0
`
`®
`
`---
`
`This book is due on the date indicated
`below and .. is~ subject to an overdue
`fine as posted at the circulation desk.
`
`EXCEPTION: Date due will be
`earlier if this item is RECALLED.
`
`Douglas l
`
`r, 7'
`
`,.
`
`/
`
`'
`;vr~-'~9ql\
`
`3 no
`
`EC 1 4 ~004
`
`JUN .2~ 1001
`
`AUG 2 0 2003
`
`MictOSoft
`
`150M/01 -92-941680
`
`Page 00004
`
`
`
`PUBLISHED BY
`Microsoft Press
`Division of Microsoft Corporation
`One Microsoft Way
`Redmond Washington
`
`98052-6399
`
`Copyright
`
`1998 by Douglas McConnaughey Boling
`
`All rights reserved No part of the contents of this book may be reproduced
`or
`the written permission of the publisher
`transmitted in any form or by any means without
`
`Library of Congress Cataloging-in-Publication Data
`1960
`Boling Douglas McConnaughey
`Programming Microsoft Windows CE
`cm
`index
`Includes
`ISBN 1-57231-856-2
`Microsoft Windows Computer
`Computers
`Title
`QA76.76.O63B623
`005.4469--dc2l
`
`Douglas McConnaughey Boling
`
`file
`
`Operating Systems
`
`1998
`
`98-39279
`CIP
`
`Printed and bound in the United States of America
`
`123456789
`
`QMQM 321098
`
`Distributed in Canada by ITP Nelson
`
`division of Thomson Canada Limited
`
`CIP catalogue record for this book is available from the British Library
`
`Microsoft Press books are available through booksellers and distributors worldwide For further
`international editions contact your local Microsoft Corporation office Or
`information about
`contact Microsoft Press International directly at fax 425 936-7329 Visit our Web site at
`mspress .microsoft corn
`
`Win32 Win
`Active Desktop Developer Studio Microsoft Microsoft Press MS-DOS Visual
`dows the Windows CE logo and Windows NT 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
`
`Acquisitions Editor Eric Stroo
`Project Editor Kathleen Atkins
`Technical Editor Jim Fuchs
`
`Page 00005
`
`
`
`To Nancy Jane
`To Ncmcyjcme
`
`Page 00006
`
`
`
`Page 00007
`
`
`
`COntents at Wance
`
`Part Windows Programming Basics
`Hello Windows CE
`
`Chapter
`
`Chapter
`
`Chapter
`
`Chapter
`
`Drawing on the Screen
`Input Keyboard Stylus and Menus
`Windows Controls and Dialog Boxes
`
`Part II Windows CE Basics
`
`Chapter
`
`Chapter
`
`Chapter
`
`Chapter
`
`Common Controls and Windows CE
`
`Memory Management
`and the Registry
`
`Files Databases
`
`Processes and Threads
`
`Ill Communications
`
`Part
`
`Serial Communications
`Chapter
`Chapter 10 Windows Networking and lrSock
`Chapter 11 Connecting to the Desktop
`
`PartlV Advanced Topics
`
`Chapter 12 Shell ProgrammingPart
`
`Chapter 13 Shell ProgrammingPart
`
`Chapter 14 System Programming
`
`Appendix
`
`COM Basics
`
`35
`
`87
`
`149
`
`265
`
`349
`
`379
`
`493
`
`539
`
`579
`
`633
`
`709
`
`749
`
`793
`
`811
`
`Page 00008
`
`
`
`Page 00009
`
`
`
`Contents
`
`Acknowledgments
`
`Introduction
`
`Part Windows Programming Basics
`
`Hello Windows CE
`Chapter
`WHAT Is DIFFERENT ABOUT WINDOWS CE
`PROGRAMMING
`ITS STILL WINDOWS
`
`YOUR FIRST PROGRAM
`
`Chapter
`
`Drawing on the Screen
`
`PAINTING BASICS
`
`WRITING TEXT
`
`BITMAPS
`
`LINES AND SHAPES
`
`Chapter
`
`Input Keyboard Stylus and Menus
`
`THE KEYBOARD
`
`THE STYLUS AND THE TOUCH SCREEN
`
`MENUS
`
`RESOURCES
`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`CHILD WINDOWS
`
`WINDOWS CONTROLS
`
`DIALOG BOXES
`
`CONCLUSION
`
`xi
`
`xiii
`
`35
`
`36
`
`39
`
`63
`
`71
`
`87
`
`87
`
`105
`
`125
`
`127
`
`149
`
`150
`
`169
`
`208
`
`262
`
`Page 00010
`
`
`
`Contents
`
`Part
`
`ii
`
`ViIndows CE Basics
`
`Chapter
`
`Common Controls and Windows CE
`
`PROGRAMMING
`
`COMMON CONTROLS
`
`THE COMMON CONTROLS
`
`OTHER COMMON CONTROLS
`
`UNSUPPORTED
`
`COMMON CONTROLS
`
`Chapter
`
`Memory Management
`MEMORY BASICS
`
`THE DIFFERENT
`
`KINDS OF MEMORY ALLOCATION
`
`Chapter
`
`Files Databases
`
`and the Registry
`
`THE WINDOWS CE FILE SYSTEM
`
`DATABASES
`
`THE REGISTRY
`
`CONCLUSION
`
`Chapter
`
`Processes and Threads
`
`PROCESSES
`
`THREADS
`
`SYNCHRONIZATION
`
`INTERPROCESS
`
`COMMUNICATION
`
`EXCEPTION HANDLING
`
`Part
`
`Ill CommLrflcathms
`
`Chapter
`
`Serial Communications
`
`BASIC DRIVERS
`
`BASIC SERIAL COMMUNICATION
`
`THE INFRARED PORT
`
`THE CECHAT EXAMPLE PROGRAM
`
`viii
`
`265
`
`266
`
`267
`
`346
`
`348
`
`349
`
`350
`
`358
`
`379
`
`380
`
`417
`
`467
`
`491
`
`493
`
`493
`
`499
`
`507
`
`516
`
`531
`
`539
`
`539
`
`545
`
`557
`
`560
`
`Page 00011
`
`
`
`Chapter 10 Windows Networking and IrSock
`
`WINDOWS
`
`NETWORKING
`
`SUPPORT
`
`BASIC SOCKETS
`
`TCP/IP PINGING
`
`Chapter 11 Connecting to the Desktop
`
`THE WINDOWS CE REMOTE API
`
`THE CEUTIL FUNCTIONS
`
`CONNECTION NOTIFICATION
`
`FILE FILTERS
`
`Part IV Adflc.ed Topics
`
`Chapter 12 Shell ProgrammingPart
`
`WORKING WITH THE SHELL
`
`THE TASKBAR
`THE OUT OF MEMORY DIALOG Box
`
`NOTIFICATIONS
`
`CONSOLE APPLICATIONS
`
`Chapter 13 Shell ProgrammingPart
`
`THE SUPPLEMENTARY INPUT PANEL
`
`WRITING AN INPUT METHOD
`
`HARDWARE
`
`KEYS
`
`Chapter 14 System Programming
`
`THE BOOT PROCESS
`
`SYSTEM CONFIGURATION
`
`WRITING CROSS-PLATFORM WINDOWS CE APPLICATIONS
`
`COM Basics
`
`Appendix
`USING COM INTERFACES
`COM CLIENTS
`COM SERVERS
`
`Index
`
`Contents
`
`579
`
`580
`
`599
`
`626
`
`633
`
`634
`
`662
`
`667
`
`680
`
`709
`
`710
`
`716
`
`725
`
`726
`
`742
`
`749
`
`750
`
`758
`
`787
`
`793
`
`794
`
`802
`
`802
`
`811
`
`812
`
`812
`
`813
`
`815
`
`lx
`
`Page 00012
`
`
`
`Page 00013
`
`
`
`Acknowledgments
`
`Id heard stories from authors about the travails of writing
`book Still
`was unpre
`learned just how much of
`pared for the task While wrote
`team effort
`is neces
`sary to make
`book My name appears on the cover but countless others were
`involved in its creation
`
`First
`
`it
`
`there is the talented team at Microsoft Press Kathleen Atkins the project
`leader and editor of this book took my gnarled syntax and confused text and made
`readable Kathleen thanks for your words of encouragement your guidance and
`for making this book as good as it
`is The books technical editor Jim Fuchs was my
`voice in the initial editing process His judgement was so good that
`rarely had to
`correct an edit for technical reasons Many thanks also go to Cheryl Penner the copy
`editor and proofreader Elizabeth Hansford the principal compositor and Michael
`Victor who translated my stick drawings into professional
`illustrations Finally thanks
`to Eric Stroo who took
`chance and signed me to write this book Eric the sun seems
`to be out now
`was privileged to be able to mine the golden knowledge
`For technical help
`of the Microsoft Windows CE development team Special
`thanks go to Mike Thomson
`who put up with endless
`inquiries about the technical details of Windows CE On
`that Mike didnt have the answer he guided me to the folks who
`the rare occasions
`did Among those folks who helped were Dave Campbell Carlos Alayo Scott Holden
`Omar Maabreh Jeff Kelley and Jeff Blum While these guys did the best
`they could
`am of course responsible for any mistakes introduced into the text as
`their answers
`You cant write
`book of this type without hardware My thanks go to Cheryl
`Balbach Scott Nelson and the Casio Corporation for their assistance When other
`companies turned me down Casio stepped up to the plate and provided prerelease
`and hard-to-find hardware necessary to test my code Thanks Cheryl Call me if you
`need any more drop testing performed
`also owe
`debt of gratitude to the folks at Vadem Ltd It was while working at
`Vadem that was initially
`introduced to Windows CE and amazingly enough allowed
`to contribute to the creation of one of the machines youll see in the introduction
`Thanks to Craig Colvin who talked me into working at Vadem and is now busy de
`signing new and innovative Windows CE products John Zhao the president and
`Henry Fung CTO as well as the managers down the line Jim Stair and Norm Farquhar
`
`interpreted
`
`xi
`
`Page 00014
`
`
`
`Acknowledgments
`
`To all of you thanks for allowing me to disappear as the book ran behind schedule
`Id also like to thank Edmond Ku Scott Chastain Ron Butterworth Anthony Armenta
`and the rest of the Clio team
`One good friend deserves special mention Jeff Prosise started me down this
`path when he talked me into writing my first article in 1985 When you get past his
`honesty good nature and modesty youre left with one incredibly smart guy de
`voted to his family and friends Thanks Jeff for everything
`My career as writer started at the top PC Magazine There Id like to thank
`Michael Miller Jake Kirchner Bill Howard and Gail Shaffer Other folks no longer
`directly tied to the magazine but whom still
`regard as part of the PCMagazine fam
`ily are Bill Machrone Trudy Neuhaus and Dale Lewallen
`In addition thank two of the mastersCharles Petzold and Ray Duncan These
`guys along with Jeff Prosise write the best technical books on the planet
`Thanks also to the folks at Microsoft Systems Journal and Microsoft Interactive
`Developer Eric Maffei Josh Trupin and Gretchen Bilson
`thanks goes to
`special
`Joe Flanigan who introduced me to some of the folks on the Windows CE team at
`Microsoft
`
`number of musical groups that helped me through long
`Id also like to thank
`hours in front of the PC These include but arent limited to the Beach Boys the Cran
`berries Alan Parsons Project Toad the Wet Sprocket
`the Eagles and Dire Straits
`Thanks also to the Southland Corporation owners of the 7-Eleven franchise for in
`venting the Big Gulp and its more potent cousins the Super Big Gulp and the Double
`Gulp Thanks also to the Coca-Cola Corporation for providing the caffeine
`On more serious note if
`theres any one person whose name also deserves to
`be on the cover of this book its Nancy Jane Hendricks Boling my wife Nancy en
`dured
`single parent because
`year of being
`spent every spare moment in front of
`my PC and an array of Windows CE devices writing this book Thank you Nancy
`Im sure
`didnt say it enough over the past year
`love you Your name isnt on the
`cover but the book is dedicated to you must also mention two other family mem
`bersour Sons Andy
`years old and Sam born during the writing of Chapter
`Andy is well on his way to becoming the best big brother
`boy can be Sam well he
`has the cutest giggle Thanks also to Amy Sekeras for taking such good care of Andy
`and Sam
`
`Finally
`
`lack the words to adequately say thanks
`to my parents Ronald and
`Jane Boling Mom and Dad you are simply the best parents
`know have met or
`read about
`is my goal in life to attempt to be as good
`parent to my children
`as you are to Rob Chris Jay and me am truly blessed to have you as parents
`
`ever
`
`It
`
`XII
`
`Page 00015
`
`
`
`Introduction
`
`was introduced to Microsoft Windows CE right before it was released in the fall of
`1996 Windows programmer
`for many years
`was intrigued by an operating sys
`tem that applied the well-known Windows API to
`smaller more power-conserving
`operating system The distillation of the API for smaller machines 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 some
`from writing for Windows 98 or Windows NT Its those differences
`what different
`that Ill address in this book
`
`JUST WHAT IS WINDOWS CE
`Windows CE is the newest smallest and arguably the most interesting of the Micro
`soft Windows operating systems Windows CE was designed from the ground up to
`small ROM-based operating system with Win32 subset API Windows CE ex
`be
`tends the Windows API into the markets and machines that cant support
`the larger
`footprints of Windows 98 and Windows NT
`Windows 98 is
`great operating system for users who need backward compati
`bility with DOS and Windows 2.x and 3.x programs While it has shortcomings Win
`dows 98 succeeds amazingly well at this difficult
`task Windows NT on the othei hand
`is written for the enterprise It sacrifices compatibility and size to achieve its high level
`of reliability and robustness
`Windows CE isnt backward compatible with MS-DOS or Windows Nor is it
`an all-powerful operating system designed for enterprise computing Instead Win
`dows CE is
`lightweight multithreaded operating system with an optional graphi
`cal user interface Its strength lies in its small size its Win32 subset API and its
`multiplatform support
`
`PRODUCTS BASED ON WINDOWS CE
`The first products designed for Windows CE were handheld organizer type devices
`with 480-by-240 or 640-by-240 screens and chiclets keyboards These devices dubbed
`Handheld PCs were first
`introduced at Fall Comdex 96 Fall Comdex 97 saw the re
`lease of
`dramatically upgraded version of the operating system Windows CE 2.0
`
`XIII
`
`Page 00016
`
`
`
`Introduction
`
`with newer hardware in
`
`640-by-240
`
`familiar formthis time the box came with
`somewhat
`landscape screen and
`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 di
`rectly at the pen-based organizer market currently dominated by the Palm Pilot The
`portrait mode 240-by-320 screen and uses stylus-based input
`Palm-size PC sports
`number of Palm-size PCs are on the market
`today
`Palm-size PC in this case
`Figure I-i shows both
`PC in this case
`Casio A-20
`
`Casio E-1O and Handheld
`
`Figure I-i
`
`The Casio E-1O Palm-size PC and the Casio A-20 Handheld PC
`
`just as this book is being released Microsoft has introduced the Handheld PC
`greatly enhanced H/PC with new applications and which uses
`Professional which is
`the latest version of the operating system Windows CE 2.11.1 This device brings the
`compact nature of Windows CE to devices of laptop size The advantages of apply
`ing Windows CE to
`laptop device are many First the battery life of Handheld PC
`Pro is at least 10 hours far better than the 2-to 3-hour average of
`PC-compatible
`laptop Second the size and weight of the Windows CE devices are far more user
`friendly with systems as thin as
`inch weighing less than
`pounds Even with the
`large VGA screen and
`diminutive size Handheld PC Pro still sports
`keyboard
`that normal human can use The Vadem Clio Handheld PC Pro shown in Figure 1-2
`is an example of how Windows CE is being used in newer platforms The system
`
`Windows CE 2.11 is Windows CE 2.10 with
`
`few minor changes
`
`xiv
`
`Page 00017
`
`
`
`tablet-mode device This de
`standard laptop or flipped into
`can be used as
`vice is just one example of how Windows CE is expanding into new system types
`
`Introduction
`
`Figure 1-2 The Vadem Clio Handheld PC Pro
`
`in
`
`this book under its operating system
`refer to the Handheld PC Pro throughout
`version Windows CE 2.1 because the platform name Handheld PC Pro was deter
`hand in the development
`knew of and in fact had
`mined very late in the process
`use code names
`of Handheld PC Pro under its code name Jupiter However you can
`book so its operating system version had to suffice
`Other platformsAuto PC Web TV set-top boxes and embedded platforms
`designed for specific tasksare also appearing or will appear in the coming months
`Whats amazing about Windows CE is that the flexibility of the operating system al
`the time retaining the same
`to be used in all
`these diverse designs while all
`lows it
`basic well-known Win32 API
`
`WHY YOU SHOULD READ THIS BOOK
`Programming Microsoft Windows CE is written for anyone who will be writing appli
`cations for Windows CE Both the embedded systems programmer using Windows CE
`interested in porting an ex
`specific application and the Windows programmer
`for
`isting Windows application or writing an entirely new one can use the information
`in this book to make their tasks easier
`The embedded systems programmer who might not be as familiar wjth the
`Win32 API as the Windows programmer can read the first section of the book to
`
`xv
`
`Page 00018
`
`
`
`Introduction
`
`the
`
`become familiar with Windows programming While this section isnt the compre
`hensive tutorial that can be found in books such as Programming Windows by Charles
`Petzold it does provide
`base that will carry the reader through the other chapters
`in the book It also can help the embedded systems programmer develop fairly com
`plex and quite useful Windows CE programs
`The experienced Windows programmer can use the book to learn about
`differences among the Win32 APIs used by Windows CE Windows NT and Windows
`98 Programmers who are familiar with Win32 programming recognize subtle differ
`ences between the Windows 98 and Windows NT APIs The differences between
`Windows CE and its two cousins are even greater The small footprint of Windows CE
`means that many of the overlapping APIs in the Win32 model arent supported Some
`sections of the Win32 API arent supported at all On the other hand because of its
`number of areas that are
`unique setting Windows CE extends the Win32 API in
`covered in this text
`The method used by Programming Windows CE is to teach by example 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
`number of the processors supported by Windows CE are also pro
`programs for
`vided 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
`class library such as MFC
`write programs for Windows CE the examples avoid using
`the unique nature of writing applications for Windows CE Some
`which obfuscates
`the availability of MFC on Windows CE eliminates the need for
`people would say that
`direct knowledge of the Windows CE API
`believe the opposite is true Knowledge
`of the Windows CE API enables more efficient use of MFC also believe that truly know
`ing the operating system also dramatically simplifies the debugging of applications
`
`WHAT ABOUT MFC
`
`general-
`
`is that Windows CE systems arent the best platform for
`The simple fact
`purpose class library like MFC The slower processors and the significantly lower
`memory capacity of Windows CE devices make using MFC problematic Most Win
`include the MFC library in their ROM This means that the
`dows CE systems dont
`MFC and OLE32 DLLs required by MFC applications must be downloaded into the
`systems The first versions of the Palm-size PCs dont even support MFC
`place for MFC on Windows CE devices One such place might
`That said theres
`system you know will have the MFC
`be if youre designing
`custom application for
`and 0LE32 DLLs in ROM For those specific applications you might want to use MFC
`but only if you know the target environment and have configured the system with
`the proper amouni of RAM to do the job
`
`xvi
`
`Page 00019
`
`
`
`Introduction
`
`5.0
`run
`
`for
`
`sual
`
`Visual
`
`WINDOWS CE DEVELOPMENT TOOLS
`This book is written with the assumption that the reader knows
`and is at least fa
`miliar with Microsoft Windows All code development was done with Microsoft Vi
`for Windows CE under Windows NT 4.0
`5.0 and Windows CE Visual
`To compile the example programs in this book you need Microsoft Visual
`IDE DevStudio
`which is part of the integrated development environment
`standard IBM-compatible PC You also need Microsoft Visual
`ning on
`5.0 that
`Its an add-in to Visual
`Windows CE which isnt
`stand-alone product
`that produce code for the different CPUs
`incorporates components to the compiler
`supported by Windows CE Visual
`for Windows CE isnt currently available through
`information on ordering it directly from Microsoft can
`standard retail channels but
`be found on the Microsoft Web site Finally you need one of the platform SDKs for
`Windows CE These SDKs provide the custom include files for each of the Windows
`CE platforms These platform SDKs are available for free on the Microsoft Web site
`convenience Ive also included the platform SDKs available at the time of the
`As
`writing of this book on the accompanying CD
`While not absolutely required for developing applications for Windows CE
`Windows NT 4.0 is strongly recommended for the development environment
`Its
`possible to compile and download Windows CE programs under Windows 98 but
`many of the features of the integrated development environment IDE such as Win
`dows CE emulation and remote debugging arent supported
`for Windows CE wont change the outward appearance of Visual
`the tools menu Nor will
`the in
`few new tools listed under
`with the exception of
`for Windows CE prevent you from developing applications
`stallation of Visual
`for Windows CE
`for other Windows operating systems The installation of Visual
`will result in new Windows CE targets such as WCE MIPS and WCE SH and WCE x86Em
`new Win32 application
`being added to the platforms listing when youre creating
`Also Windows CE MFC AppWizard will be added to the new projects listing to assist
`in creating MFC programs for Windows CE
`
`TARGET SYSTEMS
`You dont need to have Windows CE target device to experience the sample pro
`grams provided by this book The various platform SDKs come with Windows CE
`that lets you perform basic testing of Windows CE program under Win
`emulator
`dows NT This emulator comes in handy when you want to perform initial debugging
`to ensure that the program starts creates the proper windows reacts to menu selec
`the emulator has some limitations and there simply is no
`tions and so on However
`target Windows CE system to perform final debugging and
`replacement for having
`testing for applications
`
`xvii
`
`Page 00020
`
`
`
`Introduction
`
`if
`
`number of factors when deciding what Windows CE
`You should consider
`hardware to use for testing First
`the application is to be
`commercial product
`you should buy at least one system for each type of target CPU You need to test against
`all of the target CPUs because while the source code will probably be identical
`the
`in size and so will
`resulting executable will be different
`the memory allocation foot
`print for each target CPU
`Most applications will also be written specifically for the Handheld PC or Palm-
`size PC not both Although the base operating system for both the Handheld PC and
`Palm-size PC is Windows CE the hardware underneath is vastly different The strict
`memory constraints of the Palm-size PC as well as its much smaller screen its differ
`ent orientation and its lack of
`keyboard force compromises that arent acceptable
`on Handheld PC or its larger relative the Handheld PC Pro Other constraints on
`Palm-size PC systems such as the lack of printing and TrueType support differenti
`from the Handheld PCs
`ate its environment
`demonstrate programs that can run on the Handheld PC
`In this book
`Handheld PC Pro or Palm-size PC The goal
`is to allow the lessons to be applied to
`all platforms For some examples however
`screen dimensions mean
`the different
`run better on one particular system point out the differences
`that the example will
`and the reasons they exist For example some controls might exist on only one plat
`form or the other The shells for the two platformsHandheld or Palm-sizeare also
`small set of features in Windows CE
`different and need separate coverage Finally
`are simply not supported on the smaller Palm-size PC platform
`
`WHATS ON THE CD
`The accompanying CD contains the source code for all
`the examples in the book
`Ive also provided project
`files for Microsoft DevStudio so that you can open
`preconfigured projects Unless otherwise noted the examples are Windows CE 2.0
`compatible so that they can run on most Windows CE systems available today Chap
`ter 13 Shell ProgrammingPart
`contains examples that are compiled for
`Windows CE 2.01 SO they wont run on current Handheld PCs There are some ex
`amples such as the console applications
`in Chapter 12 that are specific to the
`Handheld PC Pro and other devices running Windows CE 2.10
`When you build for
`specific platform remember
`that it might not be back
`ward compatible with earlier versions of Windows CE For example Microsoft moved
`some of the
`library support from statically linked libraries in Windows CE 2.0 into
`the operating system for Windows CE 2.01 the Palm-size PC release This reduces
`for the Palm-size PC from running
`the size of an executable but prevents code built
`Handheld PC running Windows CE 2.0 You can however compile code for
`on
`Palm-size PC
`Handheld PC running Windows CE 2.0 and have it run on
`
`XVIII
`
`Page 00021
`
`
`
`Introduction
`
`In addition to the examples the CD contains
`number of folders of interest
`the Windows CE programmer Ive included the platform SDKs for the Handheld PC
`the Handheld PC Pro SDK wasnt avail
`as well as for the Palm-size PC Unfortunately
`able in time for this release Like the other platform SDKs that one is available for
`free on the Microsoft Web site Check out the readme file on the CD for late-breaking
`information about what else is included on the CD
`
`to
`
`OTHER SOURCES
`have attempted to make Programming Microsoft Windows CE
`While
`one-stop shop
`for Windows CE programming no one book can cover everything
`nice comple
`ment to this book is Inside Windows CE by John Murray It documents the oral his
`tory of Windows CE Knowing this kind of information is crucial
`to understanding
`is Once you know the why its easy to
`just why Windows CE is designed the way it
`extrapolate the what when trying to solve problems Murrays book is great not just
`because of the information youll learn about Windows CE but also because its an
`entertaining read
`For learning more about Windows programming in general
`the clas
`suggest
`sic text Programming Windows 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 For learning more about the Win32 kernel
`suggest Jeff Richters Advanced Windows Jeff covers the techniques of pro
`API
`cess thread and memory management down to the most minute detail For learning
`more about MFC programming theres no better text than Jeff Prosises Programming
`Windows 95 with MFC This book is the Petzold of MFC programming and simply
`required read for MFC programmers
`
`FEEDBACK
`have striven to make the information in this book as accurate as possible
`While
`youll undoubtedly find errors If you find problem with the text or just have ideas
`about how to make the next version of the book better please drop me
`note at
`CEBook@DelValle.com cant promise you that Ill answer all your notes but will
`read every one
`
`Doug Boling
`
`Tahoe City California
`August 1998
`
`xix
`
`Page 00022
`
`
`
`Page 00023
`
`
`
`Part
`
`WiNDows
`PROGRAMMING BASICS
`
`III
`
`Page 00024
`
`
`
`Page 00025
`
`
`
`chapter
`
`Hello Windows CE
`
`From Kernighan and Ritchie to Petzold and on to Prosise programming books tradition
`ally start with hello world program Its
`logical place to begin Every program has
`basic underlying structure that when not obscured by some complex task it was de
`signed 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 set
`ting 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 writ
`ten on PCs running Microsoft Windows NT and debugged mainly on separate Win
`dows CEbased target devices
`While experienced Windows programmers might be tempted to skip this chap
`that theyyouat
`ter and move on to meatier subjects
`least skim the chapter
`suggest
`standard Windows program and Windows CE
`to note the differences between
`program 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
`
`that make it different
`number of unique characteristics
`Windows CE has
`from other
`Windows platforms First of all
`the systems running Windows CE are most likely not
`short list of supported CPUs
`using an Intel x86 compatible microprocessor
`Instead
`run Windows CE Fortunately the development environment
`isolates the program
`mer from almost all of the differences among the various CPUs
`
`Page 00026
`
`
`
`Part Windows Programmrng Bascs
`
`by-480-pixel
`
`keyboard Some Win
`Nor can Windows CE program be assured of
`screen or
`240-by-320-pixel portrait-style screen while others might have
`dows CE devices have
`landscape orientations in 480-by-240 640-by-240 or 640-
`screens with more traditional
`display at all The tar
`resolution An embedded device might not have
`get devices might not support color And instead of mouse most Windows CE
`touch screen On
`touch-screen device left mouse button clicks are
`devices have
`tap on the screen but no obvious method exists for delivering
`achieved by means of
`right mouse button clicks To give you some method of delivering
`right click the
`Windows CE convention is to hold down the Alt key while tapping Its up to the Win
`right mouse click
`dows CE application to interpret
`this sequence
`
`as
`
`Fewer Resources in Windows CE Devices
`The resources of the target devices vary radically across systems that run Windows CE
`number of
`When writing standard Windows program the programmer can make
`assumptions about the target device almost always an IBM-compatible PC The tar
`virtual memory system that
`hard disk for mass storage and
`get device will have
`swap device to emulate an almost unlimited amount of vir
`uses the hard disk as
`tual RAM The programmer knows that the user has
`two-button mouse
`keyboard
`these days almost assuredly supports 256 colors and
`screen reso
`and monitor that
`lution of at least 640 by 480 pixels
`that almost never have hard disks for
`Windows CE programs run on devices
`hard disk means more than just not having
`place to
`mass storage The absence of
`hard disk virtual RAM cant be created by swapping data
`store large files Without
`low-memory envi
`to the disk So Windows CE programs are almost always run in
`ronment Memory allocations can and often do fail because of the lack of resources
`program automatically when free memory reaches
`Windows CE might
`terminate
`surprisingly large impact on Windows CE
`critically low level This RAM limitation has
`programs and is one of the main difficulties involved in porting existing Windows
`applications to Windows CE
`
`Unicode
`
`programmer can count on when writing Windows CE applica
`One characteristic that
`16-bit value as
`character as
`tions is Unicode Unicode is
`standard for representing
`single 8-bit value Unicode
`opposed to the ASCII standard of encoding
`international markets because
`allows for fairly simple porting of programs to different
`the worlds known characters
`can be represented in one of the 65536 available
`Unicode values Dealing with Unicode is relatively painless as long as you avoid the
`dual assumptions made by most programmers that strings are represente4 in ASCII
`are stored in single bytes
`and that characters
`
`all
`
`character
`
`into
`
`Page 00027
`
`
`
`Chapter
`
`Hello Windows CE
`
`program using Unicode is that with each character
`consequence of
`taking up
`two bytes instead of one strings are now twice as long
`programmer must be careful
`making assumptions about buffer length and string length No longer should you as
`sume that
`260-byte buffer can hold 259 characters and
`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 NT and Windows CE
`development These types of definitions allow source-level compatibility across ASCII-
`and Unicode-based operating systems
`
`it
`
`New Controls
`Windows CE includes
`number of new Windows controls designed for specific envi
`ronments New controls include the command bar that provides menu- and toolbar-
`like functions all on one space-saving line critical on the smaller screens of Windows CE
`devices The date and time picker control and calendar control assist calendar and or
`ganizer applications suitable for handheld devices such as the Handheld PC H/PC
`and the Palm-size PC Other standard Windows controls have reduced function
`reflecting the compact nature of Windows CE hardware-specific OS configurations
`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
`target market or device Windows programmers usually just check
`adapted to
`the
`version of Windows to see whether
`is from the Microsoft Windows 3.1 95 or 98
`line or Windows NT line by knowing the version they can determine what API func
`tions are available to them Windows CE however has had four variations already in
`two years of existence the Handheld PC the Palm-size PC the Handheld PC
`its first
`Pro and the Auto PC
`number of new platforms are on their way with much in
`common but also with many differences among them Programmers need to under
`stand the target platform and to have their programs check what functions are avail
`able on that particular platform before trying to use
`set of functions tha