Re: ATL bug of CComPtr?
"George" <George@discussions.microsoft.com> wrote in message
news:B3E3937C-2992-4AFD-B6D3-13EA1E81773B@microsoft.com
In the ATL Internals book, one form of constructor of CComQIPtr is
implemented as this,
[Code]
CComQIPtr (IUnknown* lp)
{
p = NULL; if (lp != NULL) lp -> QueryInterface (*piid, (void**)&p);
}
[/Code]
I think there is a bug when QueryInterface fails, and the original
value of member variable p is overwritten.
Original value? In a constructor? Where do you believe this "original"
value would have come from, considering that the object hasn't existed
until just now?
I found the in MSVC 2008, the implementation is,
[Code]
atlcomcli.h
CComQIPtr(_In_opt_ IUnknown* lp) throw()
{
if (lp != NULL)
lp->QueryInterface(*piid, (void **)&p);
}
[/Code]
The code in the book matches VC6 (the latest version at the time the
book was written, I believe). In MSVC2003 (aka VC7.1) and above,
CComQIPtr (and CComPtr) ultimately derive from CComPtrBase. Data member
"p" belongs to CComPtrBase, which sets it to NULL in its constructor.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925