Tuesday, April 7, 2009

Win32 vs. MFC

I am, by trade, a C++ programmer. This becomes relevant.

The fundamental Windows API, somewhat inaccurately known as the Win32 API, is written in C, and from a very C-ish point of view. Many of the underlying functions and structures have gone through two fundamental architecture shifts — from 16- to 32-bit, then from 32- to 64-bit, and with a sidestep into the MIPS world along the way; between that and the slow accretion of features, its warts are in many cases are painfully visible.

Contrariwise, MFC ("Microsoft Foundation Classes," although no one ever uses that name) is written in C++, being essentially a C++ layer handling setup details and resource allocation and so forth. It provides wrapper classes for all the various structures and functions.

Despite all three of the above, I would much rather work with raw Win32 calls than deal with the many-faceted madness known as MFC. It actually has to break C++ in order to work: notably, out-of-memory failures are suddenly no longer signaled by std::bad_alloc exceptions but by the special MFC CMemoryException * (yes, I said *) because Microsoft decided a) to extend C++ to include exceptions (reasonable: Standard C++ now has them, in slightly different form) and b) to build MFC around and into their implementation of exceptions (significantly less reasonable).

Mind, when I really have my druthers I'll grab a reasonably sane C++ toolkit like wxWidgets. (GTK+, despite being C and Unix at heart, isn't bad either.) But ...

No comments: