The Need for ATL

 < Free Open Study > 



Up until this point in your COM journey, you have been writing every line of source code from scratch. Chapters 3, 4, and 5 were devoted to illustrating what can be done with "raw COM" using C++ and IDL. I hope you have found that although COM can be a bit much to swallow in one session, it can eventually be digested into fairly clear pieces. However, I would also imagine you noticed the following points about implementing COM servers "in the raw":

  • Implementing component housing requires similar code for every DLL server. In essence, what really changes is the code behind DllGetClassObject(). Based on a CLSID, create the correct class factory and return an interface pointer to the client. EXE servers are just about the same in this regard. Call CoRegisterClassObject() n times for n number of class factories, revoking them when WinMain() is shutting down.

  • COM class factories are all very similar. A class object basically requires modifying IClassFactory::CreateInstance() to specify the name of the coclass you are creating.

  • All COM objects implement IUnknown, which basically means two lines of code for every interface supported by the object, as well as hooks for reference counting.

  • Adding the correct registry entries for a COM server is (to put it kindly) a pain. Typically, servers register AppID, ProgID, CLSID, TypeLib, and interface information.

In short, COM requires lots of boilerplate code. These days, no sane developer would begin a new COM project from scratch-unless you need to learn the basic building blocks of COM. After that point, you really should adopt a component framework to help you with the repeat code demanded by COM.

The Active Template Library (ATL) supplies the help you have been longing for. This collection of C++ templates, macros, and classes is aimed at helping you develop very small and very fast COM servers. ATL contains code to assist you when developing traditional COM objects, ActiveX controls, Automation servers, MTS components, and MMC Snap Ins as well as full-blown Windows executables. As an added bonus, ATL 3.0 has extended the number of CASE tools, giving you just about as much flexibility and support as MFC developers have grown accustomed to.

Much like MFC, ATL projects begin by accessing CASE tools to provide a minimal and complete code base for the project at hand. The ATL COM AppWizard is used to create the component housing for your COM server and is typically followed by using the ATL Object Wizard to insert any number of coclasses into their new home.

Unlike MFC, ATL has much slimmer support for Windows application development. This does not imply you could not use ATL to build the next version of Microsoft Word or a high-profile graphics application. What this does imply is that ATL does not offer you the full set of wizards, data structures, and helper classes found in a Windows application framework such as MFC.

For example, there is no Dialog Data Exchange (DDX) support in ATL. You do not have utility classes (such as CPoint, CRect, CPen, and so forth) wrapping Windows drawing primitives. ATL is a component framework aimed at helping you build robust COM servers. To this end, if you are a C++ developer, ATL is the absolute best choice around. Specifically, ATL is here to help you with the following aspects of your COM server development (among others):

  • ATL supplies all necessary component housing code for DLL and EXE COM servers.

  • ATL provides support for IUnknown using a table-driven implementation of QueryInterface().

  • ATL provides a default class factory for every ATL coclass. If you require a more sophisticated class object, ATL will help you develop your own.

  • ATL provides server self-registration, avoiding messy REG file maintenance.

  • ATL also offers support for a number of COM services we have yet to discover: rich error information, dual interfaces, and connection points, as well as support for COM threading models and object aggregation.

I'm sure this partial list has you sold already, so let's begin to get our hands around the Active Template Library.



 < Free Open Study > 



Developer's Workshop to COM and ATL 3.0
Developers Workshop to COM and ATL 3.0
ISBN: 1556227043
EAN: 2147483647
Year: 2000
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net