Click here to Skip to main content
14,028,059 members
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 15 Oct 2001

New ATL Macros in Visual C++ 7

, 15 Oct 2001
Rate this:
Please Sign up or sign in to vote.
This sample demonstrates using the new ATL macros OBJECT_ENTRY_AUTO in ATL7
<!-- Download Links --> <!-- Main HTML starts here -->


The ATLMacros sample demonstrates using the new ATL macros OBJECT_ENTRY_AUTO. This replaces the BEGIN_OBJECT_MAP/OBJECT_ENTRY/END_OBJECT_MAP combination.

The sample is based on the ATL Project created by the AppWizard. If you choose to follow the steps in this document to create your own application, then ensure that in the Application settings dialog you choose 'DLL project' and you must ensure that you uncheck the 'Attributed' checkbox, otherwise the code will be created using the new C++ Attributes for the COM classes.

In VC6 the Object Map BEGIN_OBJECT_MAP/END_OBJECT_MAP was used to list all the ATL classes in the server that implemented COM classes. The Object Map was located in the server .cpp file (where WinMain() or DllMain() functions were located). To add a class to the map, the OBJECT_ENTRY macro was used. Object Maps provides support for the registration, initialization, and creation of a class.

In VC7 the OBJECT_ENTRY_AUTO macro is used for this instead.


OBJECT_ENTRY_AUTO(clsid, class )


clsid [in]   The CLSID of a COM class implemented by the C++ class named class.
class [in]   The name of the C++ class implementing the COM class represented by clsid.

So now there is no Object Map. You simply place the object entry macros at global scope in the project and it does all the work for you. The AppWizard puts this macro to the end of the ATL class header file, so you have all your class code in one place. Previously (VC6) it was easy to forget to add a class to the Object Map. Now you have all your code in one place, so it is easy to reuse existing classes since you can just copy the files that implement it and add them to the project. No more messing around with OBJECT_ENTRY macros.

The Sample Application

The Math DLL implements two COM object: Adder and Subtracter.

The Adder object has a method Add that returns the sum of two addends passed as parameters. A C++ class is implemented in Adder.h and Adder.cpp files.

Subtracter has a method Sub that returns the residual of the numbers passed as parameters. A C++ class is implemented in Subtracter.h and Subtracter.cpp files.

MathClient is a simple console application to test the Adder and Subtracter objects. It reads two numbers and an operation sign (+/-) from the command line and, depending on the operation, calls Adder or Subtracter. The operation is performed and the results outputed

You must ensure that the Math.dll file has been registered for the demonstration to work.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Igor Chouvalov
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190419.4 | Last Updated 16 Oct 2001
Article Copyright 2001 by Igor Chouvalov
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid