If you aren't using Visual Studio 2010, then you might like to use this class if your doing C++ and COM:
template <typename T>class AutoPtr { private: T* FData; public: AutoPtr(T* Value) { FInterface = Value; } ~AutoPtr() { if (FData != NULL) { FInterface->Release(); } } operator T* () const { return FInterface; } T& operator* () const { return *FInterface; } T* operator->() const { return FInterface; } T** operator&() { return &FInterface; } T* operator=(const T * rhs) { FInterface = rhs; return FInterface; } T* operator=(const IUnknown * rhs) { FInterface = rhs; return FInterface; } };