Skip to content

Commit a414c88

Browse files
committed
[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.
1 parent 544b734 commit a414c88

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sdk/lib/atl/atlcomcli.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ inline HRESULT AtlHresultFromLastError() throw()
5959
return HRESULT_FROM_WIN32(dwError);
6060
}
6161

62+
template <class T>
63+
class _NoAddRefReleaseOnCComPtr : public T
64+
{
65+
private:
66+
virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
67+
virtual ULONG STDMETHODCALLTYPE Release() = 0;
68+
};
6269

6370
template<class T>
6471
class CComPtr
@@ -173,10 +180,10 @@ class CComPtr
173180
return p;
174181
}
175182

176-
T *operator -> ()
183+
_NoAddRefReleaseOnCComPtr<T> *operator -> () const
177184
{
178185
ATLASSERT(p != NULL);
179-
return p;
186+
return (_NoAddRefReleaseOnCComPtr<T> *)p;
180187
}
181188
};
182189

0 commit comments

Comments
 (0)