CComPtr

template< class T >
class CComPtr

Parameters

T

A COM interface specifying the type of pointer to be stored.

ATL uses CComPtr and CComQIPtr to manage COM interface pointers. Both classes perform automatic reference counting through calls to AddRef and Release. Overloaded operators handle pointer operations. CComQIPtr additionally supports automatic querying of interfaces though QueryInterface.

The following code is from CFirePropNotifyEvent::FireOnRequestEdit:

static HRESULT FireOnRequestEdit(IUnknown* pUnk, DISPID dispID)
{
   CComQIPtr<IConnectionPointContainer, 
            &IID_IConnectionPointContainer> pCPC(pUnk);
   if (!pCPC)
      return S_OK;

   CComPtr<IConnectionPoint> pCP;
   pCPC->FindConnectionPoint(IID_IPropertyNotifySink, &pCP);
   if (!pCP)
      return S_OK;

   ...
};

This example illustrates the following:

#include <atlbase.h>

Class Members

See Also   CComPtr::CComPtr, CComQIPtr::CComQIPtr