Microsoft KB Archive/218982

= How to override IUnknown methods in an ATL server =

Article ID: 218982

Article Last Modified on 1/10/2006

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition

 Microsoft Visual C++ 2005 Express Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q218982

<div class="idea_section">

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support 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. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.

<div class="summary_section">

SUMMARY
This article shows how to override the IUnknown methods (AddRef, Release and QueryInterface) in an ATL server.

<div class="moreinformation_section">

MORE INFORMATION
When the client calls AddRef, Release or QueryInterface, the following functions that can be overridden are called: CComObjectRootEx<>::InternalAddRef CComObjectRootEx<>::InternalRelease CComObjectRootBase::InternalQueryInterface To override these functions, copy and paste the following functions in your ATL class: ULONG InternalAddRef {       // do something return CComObjectRootEx<_ThreadModel>::InternalAddRef; }

ULONG InternalRelease {   // do something return CComObjectRootEx<_ThreadModel>::InternalRelease; }

HRESULT WINAPI InternalQueryInterface(void* pThis, const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, void** ppvObject) {   // do something return CComObjectRootBase::InternalQueryInterface(pThis, pEntries, iid, ppvObject); }

Keywords: kbhowto kbarchitecture KB218982

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.