Automatic pointer
Use CComPtr<Ixxx> instead of COM pointer
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.
Example: COM pointer
void SomeApp( IHello * pHello ) {
IHello* pCopy = pHello;
pCopy->AddRef();
OtherApp();
pCopy->Hello();
pCopy->Release(); // It will ignore Release when OtherApp throw the exception.
}
Example: CComPtr
void SomeApp( IHello * pHello ) {
CComPtr<IHello> pCopy = pHello;
OtherApp();
pCopy->Hello();
}