Electronic Review of Computer Books

[ ERCB Home | New | Feature | Brief | DDJ | Letters | Links ]

[an error occurred while processing this directive]

Vital Statistics

Title Professional ATL COM Programming
Authors Richard T. Grimes
Publisher WROX Press
http://www.wrox.com/
Copyright 1998
ISBN 1-861001-40-1
Pages 703
Price $59.99


ATL: When the How Meets the Why

After the two bestselling books previously written for Wrox on DCOM and ATL 2.1 (Professional DCOM Programming and Beginning ATL COM Programming, respectively), prolific author Richard Grimes hit the shelves again with Professional ATL COM Programming, a new excellent title entirely devoted to ATL 3.0.

To the benefit of the less familiar with the subject, I shall remind readers that ATL, an acronym standing for Active Template Library, is a framework developed by Microsoft to simplify the utilization of COM from the standpoint of C++ developers. The third version of the library comes with the latest release of Microsoft’s most powerful development tool, Visual C++ 6.0, which also includes several wizards to further automate a variety of recurring tasks during COM programming with ATL.

The latest version of ATL, prosecuting on the path set by its predecessors, relies heavily on templates and macros to accomplish the conjunct goals of providing easy reuse of significant portions of boilerplate code while at the same time limiting the overhead in the resulting binaries.

Despite the claim in the preface stating that the ideal reader should already possess some experience of ATL programming before starting to read this manual, the always explanatory style of the author and the presence of detailed refreshers on the basics of C++ templates and ATL’s architecture should be enough to get even the newcomers up to speed. What I really deem mandatory in order to benefit from this book are a good knowledge of the C++ language and of the Visual C++ environment, plus a solid understanding of the key concepts of COM and DCOM programming at the vanilla C++ level. Previous experience with ATL will come in handy nevertheless.

The approach taken by the author in analyzing the functions and the internals of ATL is, consistent with Wrox’s Professional series, very comprehensive in the descriptions but always supported (I would even say driven) by complete and working examples. The writing style is not always brilliant and entertaining, but at least it never turns pedantic and remains acceptably dense with informative content.

The first two chapters dissect the essence of the framework in all its fundamental elements and mechanisms, thus effectively teaching how and why COM was encapsulated and supported by the ATL development team. A fair amount of room is also reserved for the Direct-To-COM proprietary extension to Visual C++, a topic not strictly necessary to understand the remaining theory but undoubtedly a desirable skill in the toolbox of the proficient and modern COM developer. Chapters 3 to 7 treat in depth the other core elements of ATL and, by reflex, of COM programming, including (but not limited to) designing and implementing interfaces, Automation, choosing the most appropriate class factories, creating brand new objects through the wizards, handling errors, and debugging. Particularly well thought out and loaded with clear explanations considering the complexity of the topic is chapter 7, whose focus is on threading and marshaling issues. Chapter 8 explains in detail the conspicuous support for connection points offered by the framework. The remaining chapters, from the 9th to the 11th, deal with a more advanced class of problems &emdash; the adoption of ATL to build objects that can handle windows and messages and expose a user interface, namely regular ActiveX controls and HTML Internet Explorer controls.

In my opinion, there are three qualities that together render this book particularly strong. The first is its completeness: Although we are not in front of a truly internals-style type of manual, there does not seem to be any relevant part of ATL forgotten or even overlooked, and the coverage never lacks accuracy. The second is the abundance of working examples, which demonstrate on the field all of the major concepts and instruments right after they have been described in theory. The number of pages taken by screenshots and code snippets is pretty high, but they are well integrated with the flow of the descriptions. The third upside of this text is surely the timeliness: At the time I am writing this review, numerous authoritative books on ATL 3.0 have been officially announced by the big publishing companies, but only Grimes’s work is really available on the shelves &emdash; and it has been so for a few months!

A negative note that rarely finds a place in technical reviews of programming books but is often instead one of the primary parameters judged by the average reader in choosing whether to buy them (or which ones to buy among the many treating the same topic): the price. This industry (or better, this branch of the editorial industry) has gone a long way in accustoming us consumers of technical books to ever increasing prices, yet this title stands above most others similar in scope. Not to say that the material contained is not worth $60 (we are still talking about 700 pages full of insights and hands-on experience on a hot topic), yet I simply cannot stop myself from thinking that the publisher has consciously speculated a bit on the price, confident that the hungry-for-knowledge readers wouldn’t have desisted from purchasing it based on the raise. I would have honestly expected $10-$15 less, but until comparable alternatives are published, there is little choice other than losing touch with the latest technologies.

-- Davide Marcato (marcato@programmers.net and http://www.DavideMarcato.com)

Note: Davide Marcato was a technical reviewer of the draft manuscript for WROX Press.


Excerpts from Professional ATL COM Programming

From Chapter 2 ("ATL Architecture"), page 108

"Registrar

The registrar is an object that parses registry scripts and uses this information to add, or remove, information from the registry. You can choose to use the registrar as an external COM object served by ATL.dll (the default), or you can statically link the registrar code to your project by defining the _ATL_STATIC_REGISTRY symbol.

Note that there are two versions of ATL.dll. One is Unicode (intended for NT), and the other is ANSI (for Windows 9x). You will find these on the Visual Studio disks in OS\System and OS\System\ANSI respectively.

To use the registrar component, you must distribute and register the appropriate ATL.dll. If the ATL object you’re developing is likely to be downloaded over the internet (perhaps as a control on a web page), ATL.dll will complicate matters. It means that any INF file related to the web page should specify that ATL.dll must be downloaded, and it must also check that the correct version is downloaded and registered. In terms of administration, a simpler option is to statically link the registrar so that only one DLL needs to be downloaded. […]"

From Chapter 7 ("Threading and Marshaling"), page 399

"Custom Marshaling

When an interface is marshaled, COM queries the object for the IMarshal interface. If no interface is returned, COM knows that it should use standard marshaling, which will mean using either a proxy object from an interface-specific proxy-stub DLL, or the Universal Marshaler.

If the object returns a valid IMarshal pointer, it says that it wants to take more control of the marshaling process. Although marshaling is usually carried out on a per-interface level (proxy and stub objects are specific to a particular interface), when an object returns a valid IMarshal pointer, it means that it will handle all interface marshaling. Smart proxies ease this responsibility, because they can create a standard marshaler and use it for a particular interface, but there will inevitably be a performance cost while the smart proxy decides whether it will handle an interface or not.

If your object is told to marshal an interface, it gives details of the context of the marshaling (marshaling is done in response to a call by CoMarshalInterface(), and its flags determine the context of the marshaling). The object will also be asked to provide information about how the object will be marshaled. Remember that the client will have to have an in-process proxy to call, and COM will have to create it, so IMarshal on the object is asked for the CLSID of the proxy object. Even if this is known, the client must make a connection to the object. Normally COM will do this and choose an appropriate transport. However, when you decide to handle marshaling yourself, you get to choose the transport but you have to write all the necessary code to initialize it, transmit data using it, and then close down this transport. I didn’t say marshaling was easy! […]"

From Chapter 10 ("Controls"), page 546

"Custom Properties

Custom properties are added to your control using ClassView. The Wizard will add the property to the project’s IDL and add stub get_ and put_ methods to your class. If the property is [bindable] or [requestedit], you should use the Attributes… button to add this ATL attribute and you’ll need to make sure that the control has a connection point map and derives from IPropertyNotifySinkCP<>. In addition, in the put_ method you should inform all connected clients, as in the case of stock properties above. Generally, you will only make custom properties [bindable] or [requestedit] if you are also writing the container &emdash; containers that are written by other people won’t know what to do with your property.

If your properties need to be made persistent, then you need to add an entry to the property map for the control. You may also consider calling SendOnDataChange() and SetDirty() in the put_ method. These methods are important for controls that can be saved as part of a compound file; SetDirty() sets a flag that indicates that the data in the control has changed since it was last saved. […]"


Table of Contents

1. COM Wrapper Classes

2. ATL Architecture

3. Interfaces

4. The ATL Object Wizard

5. Class Factories

6. Debugging and Error Handling

7. Threading and Marshaling

8. Connection Points

9. ATL Window Classes

10. ActiveX Controls

11. HTML Controls 


Quick Rating

Readability Star Star Star
Originality Star Star Star
Organization Star Star Star
Accuracy Star Star Star HalfStar
Consistency Star Star Star
Depth Star Star Star
Timeliness Star Star Star Star
Editing Star Star Star HalfStar
Design Star Star Star
Overall Value Star Star Star

Explanation of ERCB rating scale: No stars = unacceptable, 1 Star = marginal, 2 Stars = average, 3 Stars = above average, 4 Stars = exceptional.


Copyright ©1999 Electronic Review of Computer Books
Created 1/13/1999 / Last modified 1/16/1999 / webmaster@ercb.com