From a414c88daeb4ba91e0cc121f7cfbf51ef2d3151a Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sun, 18 Sep 2022 20:57:38 +0200 Subject: [PATCH] [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. --- sdk/lib/atl/atlcomcli.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/lib/atl/atlcomcli.h b/sdk/lib/atl/atlcomcli.h index cba78101d2d..e6effc2ffcf 100644 --- a/sdk/lib/atl/atlcomcli.h +++ b/sdk/lib/atl/atlcomcli.h @@ -59,6 +59,13 @@ inline HRESULT AtlHresultFromLastError() throw() return HRESULT_FROM_WIN32(dwError); } +template +class _NoAddRefReleaseOnCComPtr : public T +{ + private: + virtual ULONG STDMETHODCALLTYPE AddRef() = 0; + virtual ULONG STDMETHODCALLTYPE Release() = 0; +}; template class CComPtr @@ -173,10 +180,10 @@ public: return p; } - T *operator -> () + _NoAddRefReleaseOnCComPtr *operator -> () const { ATLASSERT(p != NULL); - return p; + return (_NoAddRefReleaseOnCComPtr *)p; } };