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:
pCPC
, calls QueryInterface on pUnk
to obtain the IConnectionPointContainer pointer. The retrieved pointer is stored in pCPC
.pCP
, to hold an IConnectionPoint pointer.pCPC
to retrieve an IConnectionPoint pointer via pCP
.#include <atlbase.h>
See Also CComPtr::CComPtr, CComQIPtr::CComQIPtr