https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a414c88daeb4ba91e0cc1…
commit a414c88daeb4ba91e0cc121f7cfbf51ef2d3151a
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sun Sep 18 20:57:38 2022 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Sun Oct 2 00:38:23 2022 +0200
[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=…
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 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;
}
};