Saturday, May 1, 1999

Programming Windows CE applications on your Windows CE machine

.KEYWORD ceprogpow0599
.FLYINGHEAD PROGRAMMING POWER
.TITLE Programming Windows CE applications on your Windows CE machine
.FEATURE
.SUMMARY At Windows CE Power Magazine, we just love these exclusive insider articles and we know you do, too. Tom Campbell is a programmer/writer for the Visual Basic team at Microsoft and an enthusiastic developer of Windows CE applications. While Microsoft provides developer tools for Windows CE development, they require you to run your tools on an NT desktop and download programs to your Windows CE device. But, you don’t have to do it that way. In this incredibly useful article, Tom takes you on a tour of exceptional tools you can use to do Windows CE development right on your Windows CE device.
.AUTHOR Tom Campbell
.BEGIN_SIDEBAR
.H1 Programming Power alert!
We want to run regular articles on Windows CE programming. If you’re a programmer and want to write, contact Denise Amrich at denise@windowscepower.com.
.END_SIDEBAR

Programming a Windows CE machine isn’t easy. First, go to your desktop machine. Boot up NT 4, Service Pack 3. Fire up Visual C++. Install the Windows CE Toolkit for Visual C++, and write a C++ program using MFC, or perhaps a straight C program.

Next, in the early stages of development, run your program on the emulator that comes with the Windows CE Toolkit, but then squirt the program down your serial cable to your Windows CE handheld when your program gets serious.

Complications? Nah. You just need to make sure it works right on the target machine, and, of course, the emulator doesn’t always work perfectly.

If you’re not a C programmer, you can use Visual Basic. Get VB for your desktop machine (running Windows NT, of course). Get the Windows CE Toolkit for Visual Basic too. Remember you’re using the VBScript language subset (not VB proper) along with a reduced forms package and fewer controls. If you discover a bug in your program when you’re away from the desktop, no problem. Just jot a note and wait until you get back to the office so you can try a bug fix.

.h1 There’s got to be a better way
Whoa! Is there a better way to get the job done? For example — now here’s a crazy thought — wouldn’t it be nice if you could actually program your Windows CE machine right on your Windows CE machine, instead of needing a separate desktop running NT, a compiler, an add-on Windows CE toolkit for the compiler, and a sluggish serial cable?

Wouldn’t it be cool if you Windows 98 users didn’t have to switch to NT on your desktop just to program your Windows CE device? Wouldn’t it be fantastic if you could actually fix bugs right there in the field, by running your programming environment on the target hardware, like the big boys do? Sure would. Just don’t look directly to Microsoft for the solution. Instead, consider one of the development systems in this article.

.H1 Conflict of interest alert
I’m a programmer/writer for the Visual Basic team at Microsoft. But don’t worry. Although I’ve programmed in both VB and C++ for years, I am not exactly thrilled by the fact that you need a big desktop machine running Windows NT to program your little Windows CE machine. On the other hand, as a Microsoft stockholder, I am most certainly thrilled to see third parties take up the challenge to provide viable programming environments that run on Windows CE devices. What’s not to like? The more ways there are to program Windows CE, the more reasons there are for people to buy Windows CE. Plus, I always like to explore new languages.

There are still reasons to go the Microsoft route, by the way. Visual C++ lets you hack Windows CE in every way possible. It generates tight, highly optimized machine code and provides full access to the Windows CE API set; I assume the creators of all the products mentioned in this article used Visual C++ and the Windows CE toolkit to create them. C++ is currently the only way to use the Windows CE structured storage system fully, and MFC (i.e., Microsoft Foundation Classes) is hugely useful in developing full C++ apps because it does so many things for you. Visual Basic for Windows CE is no match for its Windows 98/Windows NT counterpart, but it has plenty of custom controls of its own, and a forms package that makes creating small utilities and line of business applications that rely heavily on forms and databases. Its forms designer, in my opinion, beats any of the forms designers surveyed here. But for convenience, ease of use, and speed of development, every one of these products gives its Microsoft counterparts some stiff competition.

.H1 What’s in a handheld development system?
The development systems shared these characteristics:

.BEGIN_LIST
.BULLET They run on handheld Windows CE machines (and usually Palm-sized machines too);
.END_LIST

.BEGIN_LIST
.BULLET They don’t require any of Microsoft’s Windows CE Toolkits;
.END_LIST

.BEGIN_LIST
.BULLET They’re very easy on the pocketbook, ranging from free to absurdly cheap (nothing over $25);
.END_LIST

.BEGIN_LIST
.BULLET System resources are comparatively modest; a minimal installation without documentation files typically consumes only about 200-500K of permanent storage;
.END_LIST

.BEGIN_LIST
.BULLET They don’t generate native machine code or allow direct access to the Win32 APIs on your Windows CE machine, so they all require some kind of runtime support (provided by the developers at no cost).
.END_LIST

This is a new market, and these development environments must run under sharply constrained system resources.

.H1 PocketC
PocketC from OrbWorks (at http://www.orbworks.com) is the best of the languages described here for creating programs that look and feel like real Windows CE applications. While it is nowhere near as comprehensive or as fast as Visual C++, it more than compensates in ease of use and drastically lower entry costs–it runs a mere $25 for H/PC users, and–oddly–$24.95 for P/PC users. Don’t ask me. Installation is straightforward but there is no installer program.

[Actually, the pricing difference might make some sense. Sometimes, you use different prices to see if different price points perform better. But I suspect different reasoning. Back when I had a software company, we’d regularly get checks without the buyer telling us which product in our line he or she was buying. By pricing the two products slightly differently, you can tell which product to send based on the amount of the payment. — DG]

PocketC doesn’t generate machine code like Visual C++. Instead, it writes intermediate code interpreted by a freely distributable runtime, which OrbWorks calls a virtual machine. This is the same approach taken by Visual Basic up until Version 4 and by Java now. Windows CE machines are particularly well suited to the use of VMs because they tend to run client applications that don’t need incredibly fast loop or integer performance. The runtime is small, in the neighborhood of 100K. I have seen no programs written in PocketC that suffered from performance problems.

The PocketC language is nowhere near ANSI standard C. It is in fact far closer to Java or Visual Basic than C, with strings as a native data type, support for a range of hard-coded events, and no memory allocation. It’s a very small language, lacking in such features as direct access to the Win32 API, compound data structures, and macros. Despite this you can write a wide variety of applications because its library includes graphics, registry, file system, and many other functions that in turn call the Windows CE API.

PocketC has the best Web site of any of the products reviewed here, and already has a booming third-party developer’s market. If you see a game written or neat little utility for Windows CE, it’s likely written in PocketC, because it is the best of the offerings here for those chores.

Among the more interesting contributions of third parties are Visual Form Buddy from http://www.krugsoft.com/, which generates PocketC forms code, and DelC, an improved IDE (Interactive Development Environment) from http://homepages.tig.com.au/~pcdz/delc/delc.htm that has its own support for PocketC forms. PocketC also generates code for other handheld machines. It’s a bargain at $25 and the best starting point for CE development on a CE machine, at least if you know C.

.H1 PythonCE
My personal favorite of the programming systems surveyed in this article is PythonCE (at http://www.digicool.com/~brian/PythonCE/index.html), but your mileage may vary.

What appeals to me, as a programmer, is that Python, developed in the Unix world, has the most potential as a programming language, is extensible, and costs nothing. The Python language is state of the art. Its full buzzword support includes object-orientation, single inheritance, structured exception handling, modules, and packages. It also has such unusual intrinsic data types as lists and dictionaries, making it a RAD (Rapid Application Development) tool at heart.

Python is dynamic–that is, it supports what Java would call reflection at runtime but to a much greater degree. This means programs run much slower than they would in, say, PocketC, but in return you get a number of useful programming constructs, better postmortem debugging, and the ability to create programs that are self-configuring in the extreme.

Python is by far the best supported and documented of the languages in this survey, with many newsgroups, Web sites, and mailing lists for users of every stripe. If you want to create Windows CE apps that look like Windows CE apps, PocketC and some of its add-ons are a better choice, because the Windows CE-ness of PythonCE isn’t extensive. But if you want create apps using complex data structures or that need lots of good data mapping or string handling, Python’s very hard to beat.

While PythonCE doesn’t yet have support for Windows CE forms, you can bet it will. And if that doesn’t happen, you can hire a C programmer to get you there because Python was designed from the beginning to be highly extensible through C. This makes it possible for you to optimize any code you need–another distinct plus.

.H1 Pocket Scheme
If you’re a LISP or Scheme programmer (Scheme is, loosely termed, the modern standard for LISP) you can’t go wrong with Pocket Scheme (at http://www.angrygraycat.com/scheme/pscheme.htm), a full Scheme programming environment that the developer insists will always be free.

It installs quickly and easily and, while it is an alpha release, appeared to be quite robust. I am not a Scheme programmer, however, so I didn’t test the environment extensively. Scheme leans heavily toward manipulation of lists and is oriented toward console-mode output. It’s much better for writing pattern matching code, AI programs, and text processing than it is for the creation of Windows CE games or utilities. Unless, of course, the game happens to be Hangman or the utility happens to involve chewing through those many vast text files you store on your Windows CE machine.

A noteworthy feature of Pocket Scheme is that it is extensible through DLLs, although the Angry Gray Cat Web site warns darkly that its API "is not a thing of beauty. There is no documentation and no development kit: use the source." It would in fact be straightforward to develop a forms package for Pocket Scheme by writing a DLL in Visual C++.

.H1 Basice
Basice (at http://www.jps.net/deang/basice.htm) is a language to watch. While in a rudimentary, freeware form right now, it’s already close to the QBASIC of yore, but for a Win32 host instead of DOS.

The sample programs include a simple terminal program, graph plotting, and rudimentary graphics. Another distinct improvement over GWBASIC is a simple form of code sharing through the use of a library directory. You can develop programs either interactively or using a text editor. Basice has built-in support for graphics, file handling, string handling, math functions, error handling, and serial I/O. Its documentation is amazingly good for a free product and would already be acceptable for a commercial product, although currently there’s no charge. I suspect there will be as it improves. It is well worth the price–check the Basice Web site routinely if you’re interested in programming on a Windows CE machine. It’s not yet ready for prime time, but I have high hopes for it.

.PAGE
.H1 What’s best for you?
If your primary interest is in cranking out a handy little Windows CE utility or game in the least time, PocketC is your best bet. If you’re developing a serious software project that requires compound data structures and inheritance, and if you have the Visual C++ Toolkit for Windows CE ready to add extensions, Python is the clear winner. If you’re an old LISP hack, obviously Pocket Scheme is the way to go–but check out Python nonetheless. If you’re just having fun, on a zero budget, or you’ve programmed in GWBASIC or QBASIC, Basice is fine place to start.

.BEGIN_SIDEBAR
.H1 Product availability and resources
PocketC from OrbWorks is available at http://www.orbworks.com.

Visual Form Buddy is available from http://www.krugsoft.com.

DelC is available http://homepages.tig.com.au/~pcdz/delc/delc.htm.

PythonCE is available from http://www.digicool.com/~brian/PythonCE/index.html.

Pocket Scheme is available at http://www.angrygraycat.com/scheme/pscheme.htm.

Basice is available at http://www.jps.net/deang/basice.htm.

.H2 Web sites for Windows CE developers
Visit HPC.net at http://www.windowsce.com.

Visit CEcity Development Software at http://www.wincecity.com/software/hpc/development.html.

Visit CEGlobe HPC Languages at http://www.ceglobe.com/software/Handheld_PC/HPC_Languages.

Visit the Windows CE by Mail website at http://www.microsoft.com/windowsce/products/tips/newsbyemail.asp.

Visit RoadCoders at http://www.roadcoders.com.

.H2 Mailing lists and news groups
There are a variety of useful Windows CE mailing lists. These include:

.BEGIN_LIST
.BULLET comp.os.ms-windows.ce
.BULLET http://lists.windowsce.com/WindowsCE-Dev
.BULLET microsoft.public.windowsce
.BULLET microsoft.public.win32.programmer.wince
.BULLET microsoft.public.windowsce.developer.betas
.BULLET microsoft.public.windowsce.developer.embedded.beta
.BULLET microsoft.public.wce21.preview
.BULLET microsoft.public.vc.etk
.BULLET microsoft.public.vb.vbce
.END_LIST
.END_SIDEBAR

.BIO Tom Campbell is a programmer/writer for the Visual Basic team at Microsoft.