[ATL] Prohibit the use of AddRef/Release on objects inside CComPtr

This mimics what MS's CComPtr is doing:
https://learn.microsoft.com/en-us/cpp/atl/reference/ccomptrbase-class?view=msvc-170#operator_ptr
The reasoning behind this is that AddRef/Release is handled by the CComPtr,
so anyone calling that is most likely not using the CComPtr correct.
This commit is contained in:
Mark Jansen 2022-09-18 20:57:38 +02:00
parent 544b734498
commit a414c88dae
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B

View file

@ -59,6 +59,13 @@ inline HRESULT AtlHresultFromLastError() throw()
return HRESULT_FROM_WIN32(dwError);
}
template <class T>
class _NoAddRefReleaseOnCComPtr : public T
{
private:
virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
virtual ULONG STDMETHODCALLTYPE Release() = 0;
};
template<class T>
class CComPtr
@ -173,10 +180,10 @@ public:
return p;
}
T *operator -> ()
_NoAddRefReleaseOnCComPtr<T> *operator -> () const
{
ATLASSERT(p != NULL);
return p;
return (_NoAddRefReleaseOnCComPtr<T> *)p;
}
};