ATL Development   «Prev  Next»
Lesson 5 Adding a COM class
Objective Add a COM class to the project.

Adding COM Class

How to Add COM Class

After generating an ATL-based server, our next step is to add COM object implementation classes. The ATL framework assumes that you are going to add one C++ class for each COM object in the server. Visual C++ supports two different ways to add a COM object into ATL: using Insert New ATL Object and using New Class.

Insert a new ATL object

An ATL object can also be added into a project using New ATL Object from the Visual C++ Insert menu. This brings up the ATL Object Wizard. To add a basic COM object, select Simple Object.

New ATL Object dialog
New ATL Object dialog

Click the Next button. This brings up the ATL Object Wizard Properties dialog.
ATL Object Wizard Properties
ATL Object Wizard Properties

We did not use this method because it does not allow us to specify more than one interface in a COM object! To add a second interface, we would have to add code manually several places within the project.

We will use New Class in this course to add a C++ implementation class for a COM object:
Adding COM Class
We have now added a C++ class, CPhBookObj, that implements COM object PhBookObj and its two interfaces, IReadPhBook and IManagePhBook. We will take a closer look at the results of our efforts, for example, files and code--in the following lessons.

COM Frameworks

Some tools are already available to help reduce the frustration induced by OLE and COM. For example, the Microsoft Foundation Class (MFC) framework is designed to make it as easy as possible for C++ developers to write applications and components that take advantage of OLE by providing a set of classes that encapsulate its use. Microsoft Visual Basic, the most popular Microsoft development tool, distances developers even further from the complexity of OLE. However, only with the release of the Visual Basic Custom Control Edition was it possible to develop COM objects using Visual Basic. Until then, Visual Basic had been a tool only for COM consumers, not for COM developers.
Certainly, developing COM objects using MFC and Visual Basic is much easier than trying to create them using raw C or C++. In fact, for all but the most advanced developers, attempting to face the wrath of COM without the shelter of a framework can be tantamount to developer suicide; those frameworks have been the only feasible approach. Along with the benevolent level of abstraction they provide, however, MFC and Visual Basic carry a fairly stiff penalty: they both saddle applications and components with a large run-time dynamic-link library (DLL). This extra freight inherent in MFC and Visual Basic has created a chasm between "lean and mean" COM development using straight C and C++ and the "dumb, fat and happy" approach taken by those frameworks.

Galileo

A few years ago, in an attempt to provide solutions to the problems facing COM developers within Microsoft, several members of the Visual C++ development team were formed into a new team created to design the Enterprise edition of Visual C++, code-named Galileo. The new team determined that internal corporate developers were adopting a multitiered strategy wherein application logic is divided into roughly three layers: user services, business services, and data services, as described in the following sidebar.

Add Com Object - Exercise

Click the Exercise link to apply what you have learned about adding a C++ implementation class to a COM object.
Add COM Object - Exercise