Export (0) Print
Expand All

CComPtr

Visual Studio 6.0

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:

  • The constructor for the CComQIPtr object, pCPC, calls QueryInterface on pUnk to obtain the IConnectionPointContainer pointer. The retrieved pointer is stored in pCPC.

  • The function declares the CComPtr object, pCP, to hold an IConnectionPoint pointer.

  • IConnectionPointContainer::FindConnectionPoint is called through pCPC to retrieve an IConnectionPoint pointer via pCP.

#include <atlbase.h>

Class Members

See Also   CComPtr::CComPtr, CComQIPtr::CComQIPtr

Show:
© 2014 Microsoft