Classic Computer Magazine Archive COMPUTE! ISSUE 168 / SEPTEMBER 1994 / PAGE 30

Continuing education. (Programming Power) (Column)
by Tom Campbell

It's more important than ever to spend your learning time wisely, With the advent of Windows and a few killer apps like Excel, FoxPro, and Win-Word, people's expectations have risen. And writing good Windows software in C takes a lot of work.

One way you can make the most of your learning time is to restrict your programming to the Win32 API, a set of conventions that will allow your program to run properly under Windows NT, Windows for Workgroups, Windows 3.1, and the upcoming Windows 4.0 (or Chicago, or whatever it's going to be called). This is a more significant achievement than you might think.

Windows. 3.1 is essentially a 16-bit operating system with memory management that takes some advantage of the 386's 32-bit design. Windows for Workgroups is an extensive retooling of Windows 3.1 with a rewritten file system that also requires a 32-bit processor. Windows NT looks almost nothing like Windows 3.1 internally and has scores of new function calls, but the old ones will work with a little rewriting and judicious use of some new macros. Windows 4.0 will resemble Windows NT internally much more than Windows 3.l.

When DOS changed, there were often serious compatibility problems, some of which were never properly resolved. It seems quaint now, but it took years for some applications to adapt to the change from the floppy-disk, no-directory file system in DOS 1 to the subdirectories in DOS 2. The primitive file system in DOS 1 lives on today in DOS 6, totally useless except for the tens of thousands of older applications that use the old function calls for file access.

Even more painful has been the transition to networked computers beginning with DOS 3 in 1984. You don't have to be a network user to be affected, either: Visual Basic 3.0 Professional won't let you use its own native files (the Access file format) unless Share is running, but its own Setup Wizard doesn't work properly with Share. Omitting network features in the operating system was a horrible mistake on IBM's part, especially considering that this company was collecting vast sums of money from its customers in the name of connectivity, which meant that you paid extra - a lot extra - for the privilege of getting computers using IBM's disparate operating systems to work together.

Finally, there's a crying need for real multitasking in professional application development. Again, you may not think you need multitasking. That's because you haven't used an advanced operating system like Windows NT - or AmigaDOS. The Amiga has boasted a preemptive multitasking OS for years, and it means among other things that Amiga users almost never wait for the hourglass: not while formatting a disk or while waiting for an application to start or while saving a two-megabyte file in a word processor. While Windows does a good job of fake multitasking, it relies on all the programs running to be willing to interrupt themselves at crucial times. They don't always do that, and it can be a real pain to write them that way.

Win32 gives you all these things and a great deal more. While some of its features are faked in its Windows 3.1 and Windows for Workgroups implementations, you can still use the Win32 API to get your programs ready for Windows 4.0. Better, they will work with future versions of Windows with virtually no changes. One of the main reasons is that an int, which up until Windows 3.1 was often assumed to be two 8-bit bytes with the more significant byte first, has become 32 bits. That's bad for compatibility. Stick to the Win32 programming guidelines, and that problem goes away. Seemingly innocuous data types such as int and long have been replaced with more precise macros such as WORD and DWORD. This will pay off later, when Windows moves to 64-bit processors and beyond.

Ready to sell your software to users in Israel or China? Good, but if you don't use Win32 guidelines, you won't be able to take advantage of Unicode and the new Windows text-handling routines. Hebrew goes from right to left. Chinese goes from top to bottom. Try writing those text-handling routines yourself. The Hebrew alphabet is about the same size as ours, but Chinese requires at least 5000 characters, a tad too many for the 255-character ANSI limitation. Unicode gives you a cool 64K of new characters actually, only about half are assigned at this point, but they already represent virtually every language known to the world's computer users).

Win32 uses the new TCHAR type natively; some clever macros route the appropriate text-related calls to new entry points. The Microsoft Win32 manuals are worth the $100 they'll cost you over the street price of $400 or so for a CD-ROM-only edition of Visual C++, but they don't cover the Microsoft Foundation Classes. That's the best way for you to get Win32 compliance if you're a C++ programmer, and it's a lot easier than programming in C.