ATL Internals: Working with ATL 8 / Edition 2

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $11.85
Usually ships in 1-2 business days
(Save 83%)
Other sellers (Paperback)
  • All (9) from $11.85   
  • New (5) from $65.72   
  • Used (4) from $11.85   


The Classic Guide to ATL–Now Updated for ATL 8 and Visual Studio 2005

Four leading Windows programming experts systematically reveal ATL’s inner workings, explaining not just how ATL works, but why it works the way it does. Client-side developers will master ATL’s resources for windowing, COM control, MFC integration, web service proxy generation, and more. Server-side programmers will discover ATL’s full COM server and object services, and its extensive support for high-throughput, high-concurrency web applications, and services. Every Windows developer will learn powerful ways to increase flexibility, reduce overhead, and maximize transparency and control.

• Discover ATL’s internals through diagrams, example code, and internal ATL implementation code

• Walk through wizards that simplify ATL usage in common applications

• Master string handling in C++, COM, and ATL

• Leverage ATL smart types, including CComPtr, CComQIPtr, CComBSTR, and CComVariant

• Understand and choose the right options for implementing IUnknown

• Create glue code that exposes COM objects from COM servers

• Use canned interface implementations to support object persistence, COM

collections, enumerators, and connection points

• Build standalone applications and UI components with ATL window classes

and controls

• Use ATL Server to develop web applications that run on Microsoft IIS

Read More Show Less

Product Details

  • ISBN-13: 9780321159625
  • Publisher: Addison-Wesley
  • Publication date: 7/21/2006
  • Series: Addison-Wesley Object Technology Series
  • Edition description: New Edition
  • Edition number: 2
  • Pages: 888
  • Product dimensions: 7.00 (w) x 9.00 (h) x 1.60 (d)

Meet the Author

Chris Tavares is currently a software development engineer in the Microsoft patterns and practices group, where he strives to help developers learn the best way to develop on the Microsoft platform. He first touched a computer in third grade, doing hand-assembly of machine code on an Intel 8080 machine with 512 bytes (yes, bytes) of memory, a hex keypad, and 7 segment LCD display. He’s been digging into computers and software ever since.

Kirk Fertitta is CTO of Pacific MindWorks, a leading provider of tools and services for electronic test and measurement. With his team at Pacific MindWorks, Kirk works extensively on code generation technology and Visual Studio extensibility. He is also a .NET/C# instructor for Pluralsight.

Brent Rector, president and founder of Wise Owl Consulting, is a noted speaker, consultant, and author, specializing in .NET, ASP.NET,

Chris Sells is a program manager for the Connected Systems Division. He’s written several books, including Programming Windows Presentation Foundation, Windows Forms Programming in C#, and ATL Internals. In his free time, Chris hosts various conferences and makes a pest of himself on Microsoft internal product team discussion lists. More information about Chris, and his various projects, is available at

Read More Show Less

Read an Excerpt


.NET has hit the Windows programmer community like a tornado, tipping over the trailer homes of the ways that we used to do things. It's pretty much swept up the needs of most web applications and service applications, as well of most of the line-of-business applications for which we previously used Visual Basic and MFC.

However, a few stubborn hold-outs in their root cellars will give up their native code only at the end of a gun. These are the folks with years of investment in C++ code who don't trust some new-fangled compiler switches to make their native code "managed." Those folks won't ever move their code, whether there are benefits to be gained or not. This book is partially for them, if they can be talked into moving their ATL 3/Visual C++ 6 projects forward to ATL 8 and Visual Studio 2005.

Another class of developers that inhabit downtown Windows city aren't touched by tornados and barely notice them when they happen. These are the ones shipping applications that have to run fast and well on Windows 95 on up, that don't have the CPU or the memory to run a .NET application or the bandwidth to download the .NET Framework even if they wanted to. These are the ones who also have to squeeze the maximum out of server machines, to take advantage of every resource that's available. These are the ones who don't have the luxury of the CPU, memory or storage resources provided by the clear weather of modern machines needed for garbage collection, just-in-time compilation, or a giant class library filled with things they don't need. These developers value load time, execution speed, and direct access to the platform in rain, sleet, or dark of night. For them, any framework they use must have a strict policy when it comes to zero-overhead for features they don't use, maximum flexibility for customization, and hard-core performance. For these developers, there's ATL 8, the last, best native framework for the Windows platform.

For clients, ATL provides windowing, COM client smart types, extensive COM control and control hosting, MFC integration (including several MFC classes that no longer require the rest of MFC), and web service proxy generation. For servers, ATL provides full COM server and object services, and extensive support for high-throughput, high-concurrency web applications and services. For both clients and services, ATL makes aggressive use of macros and templates to give you maximum flexibility and low overhead, making sure you pay for only the features you use and giving you full transparency via the source code into how those classes map their functions to the platform. For productivity, ATL provides a full set of wizards for starting and building client and server projects.


Pushing the productivity idea, in ATL 7 and Visual Studio 2003, the ATL team introduced attributed ATL, allowing ATL programmers to annotate their code using the same techniques that you would use to add metadata to IDL interfaces and coclasses (such as the uuid attribute). In fact, the wizards were so happy to show you this style of code that, in VS03, the Attributed option was on by default. However, all is not sunshine and bluebirds with attributes. In .NET and IDL, attributes are a real part of the programming model; support for them exists all the way down. In ATL, attributes are more of a compiler trick, like super-macros, generating base classes, macro maps, Registry scripts, and IDL files.

Unlike macros, however, ATL attributes are not transparent—you can't see what is going on very well. A compiler switch is included to show a representation of generated code, such as what base classes were added, but it has regressed in VS05. This has led to problems in understanding and debugging issues, which was not helped by bugs in the attribute-generated code. That's not to say that the rest of ATL is bug free (or that any software is bug free), but when it comes to problems in base classes or macros, ATL has always enabled you to replace problem functionality in several ways. In fact, code to work around problems was a big part of the first edition of this book because you could so easily sidestep problems.

Cues in VS05 indicate that attributes are no longer a major part of the ATL team's focus. For example, the compiler switch shows less information, not more, about what attributes generate. Most telling, however, is that the Attributed option in the VS05 wizards is no longer checked by default.1 For that reason, although we cover the principles of ATL attributes in Appendix D, "Attributed ATL," you won't find them sprinkled throughout the book. We believe that half-hearted attributes won't make ATL 8 programmers the happiest with their native framework of choice.


This book is for the C++/COM programmer moving to ATL 8, as provided with Visual Studio 2005. ATL was built with a set of assumptions, so to be an effective ATL programmer, you need to understand not only how ATL is built, but also why. Of course, to understand the why of ATL, you must understand the environment in which ATL was developed: COM. Instead of attempting to compress all required COM knowledge into one or two chapters, this book assumes that you already know COM and spends all its time showing you the design, use, and internals of ATL. Don Box's Essential COM (Addison-Wesley Professional, 1997) is a good source of COM knowledge, if you'd like to brush up before diving into ATL.


With the exception of the first chapter, this book is arranged from the lowest levels of ATL to the highest; each chapter builds on knowledge in previous chapters. The first chapter is a brief overview of some of the more common uses for ATL and the wizards that aid in those uses. Whenever things get too detailed in the first chapter, however, we refer you to a subsequent chapter that provides more in depth coverage.

Chapters 2 through 5 present the core of ATL. Chapter 2, "Strings and Text," covers the messy world of string handling in C++, COM, and ATL. Chapter 3, "ATL Smart Types," discusses ATL smart types, such as CComPtr, CComQIPtr, CComBSTR, and CComVariant. Chapter 4, "Objects in ATL," discusses how objects are implemented in ATL and concentrates on the great range of choices you have when implementing IUnknown. Chapter 5, "COM Servers," discusses the glue code required to expose COM objects from COM servers. Chapter 6, "Interface Maps," delves into the implementation of IUnknown again, this time concentrating on how to implement QueryInterface; this chapter shows techniques such as tear-off interfaces and aggregation. Chapters 7, "Persistence in ATL"; 8, "Collections and Enumerators"; and 9, "Connection Points," discuss canned interface implementations that ATL provides to support object persistence, COM collections and enumerators, and connection points, respectively. These services can be used by components that might or might not provide a user interface. Chapters 10, "Windowing"; 11, "ActiveX Controls"; and 12, "Control Containment," concentrate on building both standalone applications and user interface components. These chapters cover the ATL window classes, controls, and control containment, respectively. Finally, Chapters 13, "Hello, ATL Server," and 14, "ATL Server Internals," cover ATL Server, which lets you build web applications on IIS. Chapter 13 introduces ISAPI and ATL Server, and Chapter 14 looks under the hood of ATL Server.

Much of what makes the ATL source difficult to read is its advanced use of templates. Appendix A, "C++ Templates by Example," provides a set of examples that illustrate how templates are used and built. If you've seen ATL source code and wondered why you pass the name of a deriving class to a base class template, you will find this appendix useful. Appendix B, "ATL Header Files," provides a list of the ATL header files, along with descriptions to help you track down your favorite parts of the ATL implementation. If you're already an ATL 3 programmer and you want to hit the ground running on what's new in ATL 8, Appendix C, "Moving to ATL 8," is for you. Finally, if you'd like an introduction to attributes (and a bit more information about why we've relegated attribute coverage to a lowly appendix), you'll want to read Appendix D, "Attributed ATL."


When writing these chapters, it became necessary to show you not only diagrams and sample code, but also internal ATL implementation code. This book often becomes your personal tour guide through the ATL source code. To help you distinguish author-generated code from Microsoft-employee-generated code, we've adopted the following convention:

// This code is author-generated and is an example of what you'd type.// Bold-faced code requires your particular attention.CComBSTR bstr = OLESTR("Hello, World.");

// Code with a gray background is part of ATL or Windows.CComBSTR(LPCOLESTR pSrc) { m_str = ::SysAllocString(pSrc); }

Because the ATL team didn't write its code to be published in book form, we often had to reformat it or even abbreviate it. Every effort has been made to retain the essence of the original code, but, as always, the ATL source code is the final arbiter.

Sample Code and Further Information

More information about this book, including the sample source code, is available at On that site, you'll also find contact information so that you can report errors or give feedback.


1 Except for when generating an ATL Server Web Service project, when the Attributed Code option is checked and disabled so that you can't uncheck it.

Read More Show Less

Table of Contents

Ch. 1 Hello, ATL 1
Ch. 2 Strings and text 43
Ch. 3 ATL smart types 99
Ch. 4 Objects in ATL 175
Ch. 5 COM servers 243
Ch. 6 Interface maps 299
Ch. 7 Persistence in ATL 345
Ch. 8 Collections and enumerators 381
Ch. 9 Connection points 441
Ch. 10 Windowing 489
Ch. 11 ActiveX controls 567
Ch. 12 Control containment 631
Ch. 13 Hello, ATL server : a modern C++ Web platform 699
Ch. 14 ATL server internals 739
App. A C++ templates by example 787
App. B ATL header files 799
App. C Moving to ATL 8 803
App. D Attributed ATL 815
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 2 Customer Reviews
  • Anonymous

    Posted August 8, 2006

    many legacy issues

    Tavares and his co-authors present a specialised guide to the latest version of Active Template Library. It's for the C++ programmer on a Microsoft machine, who is also familiar with the Component Object Model. The authors specifically state that you really do need expertise in the latter. The book deals with various legacy issues, mostly dating back to MFC, which is now largely deprecated. But there are also other aspects that are grubby and mostly unavoidable. For example, when dealing with character types, there is an abstraction called OLECHAR. Under Win32, it maps to wchar_t, while under Win16 [and the Mac] it maps to char. The need for this was due to the hardware improvements that took us from 16 bit CPUs to 32 bits. A transition that occurred mostly in the 80s. But for Microsoft, the legacy code remains in use. So there has to be low level logic that maps the character type to an actual appropriately sized memory allocation. By the way, don't think this issue is confined to Microsoft. C code from that era that was developed for Unix machines, and which might still be in use, often has a similar problem. C macros dealing with this are a notorious source of porting errors. The text deals with many other aspects of ATL. Some, like collections and enumerations, are very cleanly done. These classes are inherently meant to be high level abstractions. And the C++ code examples that use these are very easy to follow. The discussion of this also includes some sample Visual Basic code. (Most of the book has C++ code.)

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 8, 2008

    No text was provided for this review.

Sort by: Showing all of 2 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)