https://git.reactos.org/?p=reactos.git;a=commitdiff;h=69893ccf3824da558e75d3...
commit 69893ccf3824da558e75d376d3f6ac2fb1292711 Author: Mark Jansen mark.jansen@reactos.org AuthorDate: Sun Aug 5 11:48:31 2018 +0200 Commit: Mark Jansen mark.jansen@reactos.org CommitDate: Sun Aug 19 17:35:18 2018 +0200
[ATL] Improve the order of operations in CComPtr and CComQIIDPtr --- sdk/lib/atl/atlcomcli.h | 60 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-)
diff --git a/sdk/lib/atl/atlcomcli.h b/sdk/lib/atl/atlcomcli.h index 229c585fdd..ad1582a6ca 100644 --- a/sdk/lib/atl/atlcomcli.h +++ b/sdk/lib/atl/atlcomcli.h @@ -87,23 +87,49 @@ public:
T *operator = (T *lp) { - if (p != NULL) - p->Release(); + T* pOld = p; + p = lp; if (p != NULL) p->AddRef(); + + if (pOld != NULL) + pOld->Release(); + return *this; }
T *operator = (const CComPtr<T> &lp) { - if (p != NULL) - p->Release(); + T* pOld = p; + p = lp.p; if (p != NULL) p->AddRef(); + + if (pOld != NULL) + pOld->Release(); + + return *this; + } + + // We cannot enable this until gcc starts supporting __uuidof + // See CORE-12710 +#if 0 + template <typename Q> + T* operator=(const CComPtr<Q>& lp) + { + T* pOld = p; + + if (!lp.p || FAILED(lp.p->QueryInterface(__uuidof(T), (void**)(IUnknown**)&p))) + p = NULL; + + if (pOld != NULL) + pOld->Release(); + return *this; } +#endif
void Release() { @@ -175,38 +201,48 @@ public: { if (lp != NULL) { - if (FAILED(lp->QueryInterface(*piid, reinterpret_cast<void **>(&p)))) + if (FAILED(lp->QueryInterface(*piid, (void**)(IUnknown**)&p))) p = NULL; } } T *operator = (T *lp) { - if (p != NULL) - p->Release(); + T* pOld = p; + p = lp; if (p != NULL) p->AddRef(); + + if (pOld != NULL) + pOld->Release(); + return *this; }
T *operator = (const CComQIIDPtr<T,piid> &lp) { - if (p != NULL) - p->Release(); + T* pOld = p; + p = lp.p; if (p != NULL) p->AddRef(); + + if (pOld != NULL) + pOld->Release(); + return *this; }
T * operator=(IUnknown* lp) { - if (p != NULL) - p->Release(); + T* pOld = p;
- if (FAILED(lp->QueryInterface(*piid, reinterpret_cast<void **>(&p)))) + if (!lp || FAILED(lp->QueryInterface(*piid, (void**)(IUnknown**)&p))) p = NULL;
+ if (pOld != NULL) + pOld->Release(); + return *this; } };