Last week at MEDC in Las Vegas I presented a lab on application development for Windows CE using the Microsoft Foundation Classes (MFC). The common theme of questions after the session were around support for MFC and end of life for MFC, many people attending the session believed that MFC is a dead technology and has been replaced with .NET and managed application development – I can certainly see why that may appear to be the case given the amount of marketing effort around .NET technologies. The reality is that MFC is alive and well and has been completely overhauled for the Visual Studio 2005 release (MFC is now shipping as MFC version 8 in VS 2005 for the desktop and for Windows CE).
So why might you use MFC for application development? Perhaps there are a number of reasons.
1. Size – The MFC runtimes are smaller than the .NET Framework/Compact Framework libraries, about 800kb for the MFC80U.DLL compared with approximately 10MB for the .NET Compact Framework
2. Real-Time – It’s possible to write real-time application code in MFC – Since MFC based applications are written in “native code” (C/C++) you are responsible for the lifetime of objects (and handles) you create in your application – Note that this may also be a down side to native/MFC application development since it’s easier to leak memory/handles/objects in a native code application.
3. Abstraction – Programming against the Win32 API can be difficult, some APIs take parameters and return a value, some take structures, some return HRESULTS – MFC hides much of this from you, and also (interestingly) has some useful classes such as CString which hide the complexities of Unicode/ASCII programming.
4. Tools Support – Programming using Win32 means that your applications typically have a large switch statement which has a number of WM_ message handlers, adding support for handlers is a manual process, MFC has some useful tools support in Visual Studio for adding Windows Message handlers, and MFC function handlers.
Some time ago I wrote a sample for a conference I was presenting at, this was a “Scribble” application, this is a simple application that tracks mouse down, mouse move, and mouse up – while the mouse is down the application captures the mouse movements into some kind of array and then draws the points when the client area needs to be refreshed.
Writing the application in Win32 means that you need to do everything for yourself, there’s no direct support for linked lists or arrays, serialization of content to/from file isn’t straight forward – when I first wrote the Win32 application it took about two hours to get working (I had a bug in my linked list code that took a while to figure out).
Writing the same application in MFC took about 20 minutes – and writing the same application in managed code took about 10 minutes.
It would appear that there is still a place for MFC application development in the embedded devices world.
I’d be interested in your comments/feedback.