| < Free Open Study > |
This chapter gave you the lowdown on COM's location transparency. We
Next we examined COM's marshaling options. Custom marshaling allows you to have complete control over the process of moving data between processes using the IMarshal interface. Standard marshaling is almost free when you write your interfaces in IDL, leaving you to the task of creating the DLL for this stub/proxy. Universal marshaling is as free as you can get, as you have no need to worry about a separate DLL to distribute; however, you must constrict all your interfaces to use variant compliant parameters, and configure each interface to point to the CLSID of the universal
We examined how to create a local server. As you have seen, this requires a new way to work with server lifetime management, as class factories must
| < Free Open Study > |
| < Free Open Study > |
| < Free Open Study > |
| < Free Open Study > |
Generate component housing with the ATL COM AppWizard.
Insert
Understand ATL's registry scripting language.
Populate your interfaces with
Learn to add properties to a COM interface.
Leverage ATL's support for COM text manipulation.
Understand ATL's debugging options.
So far, this book has focused on the development of COM DLLs and EXEs using IDL and the C++ programming language. As you may have noticed, writing your COM servers without framework support is a "labor of love" and is often not the best approach for a large-scale COM project, given the sheer amount of repeat code. On the upside, however, ATL is of little use to developers who lack a firm understanding of the underpinnings of COM, which you have
| < Free Open Study > |
| < 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
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
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
The Active Template Library (ATL)
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
Unlike MFC, ATL has much slimmer support for Windows application development. This does not imply you could not use ATL to build the
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 > |