How To Aggregate a COM Object with ATL (173823)
The information in this article applies to:
- The Microsoft Active Template Library (ATL) 3.0, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
- The Microsoft Active Template Library (ATL) 2.1, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
This article was previously published under Q173823 Note Microsoft Visual C++ .NET (2002) supports both the managed code
model that is provided by the Microsoft .NET Framework and the unmanaged native
Microsoft Windows code model. The information in this article applies only to
unmanaged Visual C++ code. SUMMARY The following steps demonstrate how to aggregate a COM
object in an ATL project:
- Add an IUnknown pointer to your class object and initialize
it to NULL in the constructor.
- Add the DECLARE_PROTECT_FINAL_CONSTRUCT macro to protect
your object from being deleted if (during FinalConstruct) the internal
aggregated object increments the reference count then decrements the count to
0.
NOTE: If you are using Visual C++.NET the Wizard adds this for
you. - Use the IUnknown pointer you defined as the second
parameter to the COM_INTERFACE_ENTRY_AGGREGATE macros. The first parameter is
the IID of the interface of the inner object that you want to
expose.
- Override FinalConstruct() to create the
aggregate.
- Override FinalRelease() to release the IUnknown
pointer.
REFERENCES Visual C++ Books Online: Visual C++ Books; C/C++ Language
and C++ Library; Active Template Library; Articles; Introduction to COM and
ATL; Introduction to COM; Aggregation
Visual C++ Books Online:
Visual C++ Books; C/C++ Language and C++ Library; Active Template Library;
Articles; Fundamentals of ATL COM Objects; Creating an Aggregate
Modification Type: | Minor | Last Reviewed: | 6/29/2004 |
---|
Keywords: | kbArchitecture kbhowto KB173823 kbAudDeveloper |
---|
|