mirror of
https://github.com/reactos/reactos.git
synced 2025-07-27 14:43:35 +00:00
[ATL] Improve the order of operations in CComPtr and CComQIIDPtr
This commit is contained in:
parent
bb5f8cfccb
commit
69893ccf38
1 changed files with 48 additions and 12 deletions
|
@ -87,24 +87,50 @@ public:
|
||||||
|
|
||||||
T *operator = (T *lp)
|
T *operator = (T *lp)
|
||||||
{
|
{
|
||||||
if (p != NULL)
|
T* pOld = p;
|
||||||
p->Release();
|
|
||||||
p = lp;
|
p = lp;
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
p->AddRef();
|
p->AddRef();
|
||||||
|
|
||||||
|
if (pOld != NULL)
|
||||||
|
pOld->Release();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *operator = (const CComPtr<T> &lp)
|
T *operator = (const CComPtr<T> &lp)
|
||||||
{
|
{
|
||||||
if (p != NULL)
|
T* pOld = p;
|
||||||
p->Release();
|
|
||||||
p = lp.p;
|
p = lp.p;
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
p->AddRef();
|
p->AddRef();
|
||||||
|
|
||||||
|
if (pOld != NULL)
|
||||||
|
pOld->Release();
|
||||||
|
|
||||||
return *this;
|
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()
|
void Release()
|
||||||
{
|
{
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
|
@ -175,38 +201,48 @@ public:
|
||||||
{
|
{
|
||||||
if (lp != NULL)
|
if (lp != NULL)
|
||||||
{
|
{
|
||||||
if (FAILED(lp->QueryInterface(*piid, reinterpret_cast<void **>(&p))))
|
if (FAILED(lp->QueryInterface(*piid, (void**)(IUnknown**)&p)))
|
||||||
p = NULL;
|
p = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
T *operator = (T *lp)
|
T *operator = (T *lp)
|
||||||
{
|
{
|
||||||
if (p != NULL)
|
T* pOld = p;
|
||||||
p->Release();
|
|
||||||
p = lp;
|
p = lp;
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
p->AddRef();
|
p->AddRef();
|
||||||
|
|
||||||
|
if (pOld != NULL)
|
||||||
|
pOld->Release();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *operator = (const CComQIIDPtr<T,piid> &lp)
|
T *operator = (const CComQIIDPtr<T,piid> &lp)
|
||||||
{
|
{
|
||||||
if (p != NULL)
|
T* pOld = p;
|
||||||
p->Release();
|
|
||||||
p = lp.p;
|
p = lp.p;
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
p->AddRef();
|
p->AddRef();
|
||||||
|
|
||||||
|
if (pOld != NULL)
|
||||||
|
pOld->Release();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T * operator=(IUnknown* lp)
|
T * operator=(IUnknown* lp)
|
||||||
{
|
{
|
||||||
if (p != NULL)
|
T* pOld = p;
|
||||||
p->Release();
|
|
||||||
|
|
||||||
if (FAILED(lp->QueryInterface(*piid, reinterpret_cast<void **>(&p))))
|
if (!lp || FAILED(lp->QueryInterface(*piid, (void**)(IUnknown**)&p)))
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
|
||||||
|
if (pOld != NULL)
|
||||||
|
pOld->Release();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue