The Future of ATL and MFC

[Previous] [Next]

Although ATL certainly represents a significant milestone in the history of COM development, it doesn't signal the end of the line for MFC, despite the paranoia of some panic-stricken developers. When ATL was first released, nervous developers everywhere immediately began to ask some pointed questions: What is the future of MFC? Is Microsoft going to continue to improve and support MFC, or will ATL be positioned as its replacement? Because MFC has without question become the framework of choice for Windows development under C++, these are good questions. Indeed, because of the sheer number of developer-hours invested in MFC, any attempt to discontinue support for it would be met with a great deal of resistance, to say the least. Well, MFC developers can rest assured that Microsoft has no plans to abandon MFC anytime soon. The goals of MFC and ATL are different but complementary, so both should be around for a long time.

The Benefits and Drawbacks of MFC

The goal of MFC is to make it as easy as possible for C++ developers to create robust Windows applications without sacrificing application performance. For that reason, the MFC class wrappers around the Windows API are, by design, wide and shallow. In other words, although it encapsulates many different APIs, the abstraction layer between the MFC classes and the native Win32 functions under the hood is noticeably thin. For example, the CWnd::SendMessage function does nothing more than call the SendMessage function exposed by the Windows API. Although this approach is frustrating to some developers—especially those who want to develop Windows-based applications without having to invest the time to understand the ins and outs of the Windows programming model—it is most often a good trade-off. It simplifies application development without selling out on speed. Of course, applications built using MFC will suffer some performance penalty compared to those built with the raw Windows API, but for robust, large-scale applications, the maintainability of MFC code more than makes up for any slowdown in speed.

Unfortunately, MFC support for OLE and COM doesn't follow the same model as its support for the Windows API. Although MFC's window classes contain a substantial number of inline wrappers (à la CWnd::SendMessage), its OLE classes aren't nearly as lightweight. As a result, MFC is less suited for middle-tier COM object development than it is for Windows development or even OLE development. Until recently, the COM limitations of MFC have been largely forgivable—ActiveX controls developed with MFC are perfectly adequate for use in end-user applications written in Visual Basic and MFC. And when it comes to traditional OLE support—OLE document servers, compound documents, containers, and so on—MFC is the best choice. However, the recent trend toward client/server Internet applications and the three-tier architecture described earlier has exposed two problems. First, even the smallest components created using MFC are generally considered too large for use within a Web browser, especially considering the time it takes to download the associated DLLs. Second, MFC is not well suited for creating server components that provide no user interface but must simultaneously support multiple threads of execution. Thus, whereas MFC still has something to offer future Windows applications, it falls short when it comes to developing COM objects in the business services tier.


In a way, ATL is to COM what MFC is to the Windows API. The goal of ATL is to provide a thin but effective wrapper around the most common COM interfaces without sacrificing component performance. Despite this similarity, however, the designs of MFC and ATL differ in several key ways:

  • MFC contains an interconnected hierarchy of classes, whereas ATL is a set of disjoint templates. This difference means that with ATL you don't pay the size/speed penalty for a given feature unless your component actually uses it.
  • MFC is linked to a project as a static library or a DLL, but ATL is compiled as source code. Because there are no OBJ files to link to, ATL requires no run-time DLL redistribution.1
  • MFC supports a single-inheritance model, whereas the functionality of an ATL component depends entirely on the use of multiple inheritance. Specifically, a component that supports several different COM interfaces will inherit from several different associated ATL templates.
  • Over time, MFC has grown considerably. As the expectations placed on Windows applications have increased, so have the size and feature set of MFC. Although a similar progression is likely as the use of ATL becomes more prevalent, ATL's use of templates rather than regular inheritance will almost assuredly prevent class proliferation.

A Framework by Any Other Name

If you were to study the scenery in the offices and cubicles of a thousand different Windows developers, you'd likely notice two recurring themes. First, you would see a shocking number of empty soda cans—after all, if the periodic table had been developed by programmers, it would have contained only three elements: carbonated water, sugar, and caffeine. Second, you would notice an abundance of MFC class hierarchy posters on the walls. These posters are likely as much status symbols as reference materials. MFC follows a very regimented, hierarchical, singly inherited class model. It doesn't take very long to see that just about everything inherits from CWnd, CObject, or CCmdTarget.

In stark contrast, ATL is composed almost entirely of independent base classes that are "templatized."(You hear that word a lot in the C++ community, even though our spelling checker doesn't like it.) It has been said that the best thing about the ATL framework is that it isn't a framework at all. Indeed, if an ATL poster is ever published, the class layout will be very, very flat.

Inside Atl
Inside ATL (Programming Languages/C)
ISBN: 1572318589
EAN: 2147483647
Year: 1998
Pages: 127 © 2008-2017.
If you may any questions please contact us: