May 1998
Microsoft Windows CE 2.0: Its Not Just for Handheld PCs Any More |
If there is confusion about the role for Windows CE, it is due to the fact that until recently there was only one product that used Windows CE: the Handheld PC. In January of this year, Microsoft announced two more Windows CE-powered devices: the Auto PC and the Palm-size PC (P/PC). |
This article assumes you're familiar with Win32 |
Paul Yao has spent the last decade writing books and training corporate clients on Windows programming topics. Hes now created the first workshops available on Windows CE. He can be reached at
1-800-942-3535, or on email at 73717.3041@compuserve.com.
|
If your impression
of Windows® CE is that it's a pared-down version of Windows 95, or that, like its first incarnation, it can be used only on the Handheld PCs, you should take a closer look at version 2.0. Designed from scratch to be small, portable, fast, and scalable, Windows CE 2.0 is far more comprehensive than you may imagine.
Before diving too deep into the technical details, it is worthwhile to examine the motivations behind the design of Windows CE. Three emerging trends represent massive opportunity for the software industry and direct applicability for Windows CE. First, very fast, low-cost, low-power, 32-bit microprocessors are becoming ubiquitous. Everywhere you look (industrial monitoring, medical equipment, point of sale terminals, multimedia consumer appliances, smart phones, customer kiosks, and even cars), an intelligent device is making our work and home lives easier and more efficient. Second, mobile computing is becoming the modus operandi of the modern worker. Millions of traveling professionals, telecommuters, and field representatives (real-estate agents, car appraisal experts, and sales reps to name a few) are demanding more powerful, longer lasting computing power in ultra portable forms. Finally, the convergence of entertainment, information, and technology in the home will fundamentally change the way millions of people spend their leisure time. While digital convergence has been hyped for years, products such as DSS receivers, high-definition digital TV, and DVD players have already started to work their way into millions of homes. All this technology is rendered pretty useless if it can't communicate and exchange information with one another. Clearly, the importance of the Internet as a communications and information delivery infrastructure almost goes without saying. As you might expect, support for standard protocols (TCP/IP) and formats (HTML) is a fundamental requirement for any device powered by Windows CE. So let's explore the details of each of the Se from the developer's perspective.
Publicly Announced Devices
|
Figure 1 A Handheld PC |
|
Figure 2 A Palm-size PC |
|
Figure 3 An Auto PC |
Small
Modular and Configurable
Portable
Connected
Compatible
Real Time
Hardware
|
Input Devices
Output Devices
|
Communication Devices
Storage Devices
Windows CE Operating System Features
System Components
The Win32 API
|
|
The Unicode version of this function is called GetWindowTextW, and the multibyte version (ANSI version) is called GetWindowTextA. Although you can explicitly call the functions with the W and the A prefixes, most programmers rely on a layer of macros to resolve to one or the Other (the default is ANSI). An example of this applied to data structures can be seen with the LOGFONT structure. The Unicode name is LOGFONTW and the ANSI name is LOGFONTA. Only Unicode versions of functions and data structures that contain character strings exist on Windows CE.
While the change of function names and data structures is somewhat transparent to programmers, there are other issues that you must deal with when writing Unicode-compatible code. The most obvious is in the way that constants, both character strings and single character values, are defined. Here is an ANSI string and an ANSI character: |
|
An equivalent Unicode string follows. Note the use of L before both the string and the character constants: |
|
Other issues include different C runtime functions: wcscpy copies a Unicode string, while strcpy copies an ANSI string. There are still more issues you'll need to contend with, however; more complete information can be found in Nadine Kano's book Developing International Software (Microsoft Press, 1995).
A key selling feature of Windows NT is security, and the Win32 API itself exposes quite a few mechanisms for controlling the security of objects created. When starting processes (CreateProcess), opening files (CreateFile), or creating file mapping objects (CreateFileMapping), you encounter a reference to security attributes (LPSECURITY_ ATTRIBUTES). When programming for Windows CE, which does not have any support for security, you set such parameters to NULL. The UI API is significantly stripped down from what you find on a desktop API. Only a subset of menuing calls are supported, and some old favorites, like GetMenu to query the menu handle from a window handle, have not been implemented on Windows CE. There is, however, reasonable dialog box, dialog box control, and property sheet support. Windowing support is substantially pared down, with fewer window and class styles, and no support for the MDI. Of all the parts of Windows, GDI seems to have been pared down the most. The list of features not supported includes metafiles, coordinate mapping, rotation, and bezier drawing. You can still draw text with TrueType fonts; the Handheld PC ships with seven TrueType fonts. You can draw lines, but the available functions have been pared down so you must call Polyline, and don't have the Option of using MoveToEx/LineTo, PolyPolyline, or even PolylineTo. You can draw raster graphics, since support for all raster operators (ROP2, ROP3, and ROP4) is included. Starting with Windows CE 2.0, printing is supported, through either serial link or infrared port. While becoming small and fast, GDI still retains enough functionality to run Microsoft Internet Explorer 4.0. DLLs on Windows CE seem to have all the features of DLLs on the desktop. That includes the ability to create global variables that are visible in all processes that use a DLL (by default, global variables in a DLL are private to the process address space in which a DLL runs). To define shared global variables, you bracket the variables to be shared between two #pragma statements: |
|
The global variable must be initialized for this to work. the Only other thing you need to do is to create an entry in your DLL's .DEF file, like the following: |
|
It's worth pointing out that the name of the shared section created is ".shared", but there's nothing special about this name. I use the leading period since this seems to be the convention for section names. But you could just as well create a shared section named SweeneyTodd. Also, the size of the shared section you create can be as large as you'd like it to be.
The final note I'd like to make on the API has to do with the memory API. Support for global atoms doesn't exist in Windows CE, which mostly were used for the DDE, which is also not supported. The GlobalAlloc function, a decorated hero of the segmented programming wars, has been officially retired. Its younger cousin LocalAlloc is alive and well on Windows CE. Just like on Windows NT, this function allocates from the process heap (that is, it basically calls GetProcessHeap and HeapAlloc). One type of memory that is supported is thread local storage, which includes the type you request by calling TlsAlloc, as well as the kind you declare using the __declspec(thread) keyword. Both appear to work just fine on Windows CE.
Multithreading
Exception Handling
ActiveX Support
RAPI Support
Windows, Windows Everywhere
From the May 1998 issue of Microsoft Systems Journal.
|