tags:

views:

208

answers:

4

I've never worked with COM before, and I've been tasked with writing an application that uses some third party COM objects. If anyone could point me to some good tutorials on how to use them it would be much appreciated. More immediately, it appears that I don't have the Active Template Library installed. I've searched online but can't figure out how to get it.

+1  A: 

It's part of Microsoft Visual Studio (but not the Express Edition.)

Dan Breslau
+1  A: 

I think you have to own a copy of Visual Studio 2005 or 2008 (not Express) to get ATL. If you have one of those installed, but you don't have ATL then go to "Control Panel:Add/Remove Programs" and do a "Modify" install (with the program CD or DVD in the drive) and make sure the box for ATL is checked.

jeffm
+3  A: 

As Dan pointed out, these are distributed with Visual Studio.

If you don't have Visual Studio, you can get the ATL libraries from one of the Microsoft Visual C++ Redistributable packages:

Note: The ones marked 2005 are version 8 (atl80.dll), the ones marked 2008 are version 9 (atl90.dll).

R. Bemrose
That's not going to get you the headers so that you can actually write ATL code, right?
jeffm
I've never done work with ATL. I just assumed it was done via DLL calls.
R. Bemrose
+1  A: 

As for tutorials:

I haven't found a really good one online. There are a few OK pages on using ATL/COM:

  • The Active Template Library Makes Building Compact COM Objects a Joy by Don Box (veteran guru of COM). This article starts: "I love COM. COM is good. Like a fine pilsner or ale, COM never disappoints. In fact, the more I look at COM, the more I like it. Unfortunately, I work in C++, and C++ does not share my appreciation for the finer things in life." Despite the Grand Master's proselytizing, and the fact that it's 12 years old now, it's a pretty good article...
  • Mike Dunn's excellent tutorial on COM on CodeProject.
  • DevGuy's C++ COM Tips -- kind of a hodgepodge of links and suggestions.
  • The COM Programmer's Cookbook -- this ancient (1995) article isn't bad, despite its age and the fact that it describes implementing COM objects in C rather than C++ (explicit vtables!)


I'm a little rusty myself w/ COM and ATL, but if I remember right, the classes you're going to want to learn that you'll use the most (especially if you are using someone else's COM objects rather than implementing your own) are CComBSTR, CComPtr, and CComVariant. Also the #import statement in Visual C++ makes using external COM objects much easier, it generates a smart pointer class for you from an external DLL or EXE.

If you're going to be implementing COM objects, I would strongly recommend getting a copy of ATL Internals (there's a newer edition out now covering ATL v8). Yes it does go into some gory detail in sections, but even as an intro book it's fairly well written.

If you've never used COM before, the "classic" books Essential COM and Effective COM are very good and you can probably get them inexpensively from your favorite sources of used books. You're also going to want to be very familiar with the RAII idiom, if you aren't already.

The newsgroup microsoft.public.vc.atl is very good for asking particular questions. (they tend to be more gruff there than on StackOverflow, though)

Beware: There are lots of little gotchas with COM, although ATL does help it become a lot easier & without a lot of bloat. The "simulated dynamic binding" techniques aka CRTP are useful in the C++ world, not just in the context of ATL/COM but especially if you are developing a library of reusable classes that you want to subclass or mixin in situations where only one instance is present at a time (e.g. a class CSpiffyFramework that provides mixin functionality that you want to reuse a lot, and you have a derived class that you want to include that functionality, and it's not part of a virtual object model so you don't really need a vtable).

Good luck!

Jason S