Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

Using STL with MFC and ATL

This section will briefly introduce how to use STL with MFC and introduce the Active Template Library (ATL).

Using STL with MFC

The MFC Library is a set of more than 100 classes. All of the classes are tested and optimized, and the MFC Library contains data structure classes similar to STL—such as arrays, lists, and string lists. MFC is quite sufficient when compared to STL, and when it comes down to it, you probably won't come to a point where you have to have STL. When you are using MFC, however, the advantage of a lightweight program is lost, because you must bring along the DLL with distribution. So, what advantage is there in using STL with MFC?

Using STL with MFC enables easier traversal through MFC window containers. Thus, you want to use STL with MFC to help simplify MFC use and expand its use with the STL algorithms.

Introduction to ATL

ATL stands for Active Template Library. This library is designed to provide a way to create COM components in a fast and easy manner, and they leave only a small memory footprint. With ATL, you can create COM objects, Automation Server controls, and Active X controls, as well as provide built-in support for fundamental COM interfaces. ATL is an excellent partner to STL in that ATL has no provisions for data structures and algorithms, and STL fits that bill nicely.

Remember that template libraries are distributed as source code, which is a major advantage compared to function libraries. Because ATL is a template library, it only has to include the source needed in the executable, unlike MFC.

ATL Versus MFC

Which one should you use with STL? In short, use ATL to create a COM component when all of the built-in functionality of MFC is not necessary. When the component that is being created is nonvisual, ATL is most likely the better choice. ATL implementation results in faster components that use much less memory and do not carry the excess luggage of DLLs.

Share ThisShare This

Informit Network