#pragma once #include "atlbase.h" template class CSxApwComPtr; /* like what FusionHandle does */ template class CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer { public: CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer(CSxApwComPtr* p) : m(p) { } operator CSxApwComPtr*() { return m; } operator T**() { return &(*m).p; } operator void**() { return reinterpret_cast(operator T**()); } CSxApwComPtr* m; }; template class CSxApwComPtr : public ATL::CComQIPtr { private: typedef ATL::CComQIPtr Base; public: ~CSxApwComPtr() { } CSxApwComPtr(const CSxApwComPtr& that) : Base(that) { } CSxApwComPtr(T* pt = NULL) : Base(pt) { } void operator=(T* pt) { Base::operator=(pt); } CSxApwComPtr(IUnknown* pt) : Base(pt) { } void operator=(IUnknown* pt) { Base::operator=(pt); } T* operator->() const { return Base::operator->(); } CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer operator&() { return CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer(this); } }; //Specialization to make it work template<> class CSxApwComPtr : public ATL::CComQIPtr { private: typedef T IUnknown; typedef ATL::CComQIPtr Base; public: ~CSxApwComPtr() { } CSxApwComPtr(const CSxApwComPtr& that) : Base(that) { } CSxApwComPtr(T* pt = NULL) : Base(pt) { } void operator=(T* pt) { Base::operator=(pt); } T* operator->() const { return Base::operator->(); } CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer operator&() { return CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer(this); } };