CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    ATL bug of CComPtr?

    Hello everyone,


    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);
    }
    I think there is a bug when QueryInterface fails, and the original value of member variable p is overwritten.

    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);
    	}
    Seems the bug is fixed? Is it a bug in old version of ATL or a bug in the book? :-)


    thanks in advance,
    George

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ATL bug of CComPtr?

    You'll have to check the ATL source in the older versions to find out if it's a code or a book issue.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: ATL bug of CComPtr?

    George, I really hate to disappoint people, but that p would be overwritten anyway:

    From MSDN: IUnknown::QueryInterface
    ppvObject


    [out] Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObject contains the requested interface pointer to the object. If the object does not support the interface specified in iid, *ppvObject is set to NULL.
    Best regards,
    Igor

  4. #4
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: ATL bug of CComPtr?

    Thanks Arjay and Igor,


    Question answered. My carelessness this time. :-)

    Quote Originally Posted by Igor Vartanov
    George, I really hate to disappoint people, but that p would be overwritten anyway:

    From MSDN: IUnknown::QueryInterface

    regards,
    George

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured