Re: Who's in charge of AddRef'ing?



alamaison <newsgroups@xxxxxxxxxxx> wrote:
Roman Ryl... wrote:

CComPtr<IChild> m_pChild;

STDMETHOD(get_child)(IChild** ppChild)
{
if(!ppChild)
return E_POINTER;
*ppChild = CComPtr<IChild>(m_pChild).Detach(); // leave AddRef on
stack, in the out'ted variable

I'm not sure this is a good idea for a 'get' method. Detach()
destroys the existing reference (m_pChild) which CopyTo() does not.

Note that in the example, Detach is called on a temporary CComPtr object
holding a copy of m_pChild, not on m_pChild itself. When this copy was
constructed, AddRef was called. The net effect is equivalent to CopyTo,
though more verbose.
--
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


.



Relevant Pages

  • Re: Whos in charge of AddRefing?
    ... Roman Ryl... ... STDMETHOD(IChild** ppChild) ... stack, in the out'ted variable ... Detach() destroys ...
    (microsoft.public.vc.atl)
  • Re: Whos in charge of AddRefing?
    ... STDMETHOD(IChild** ppChild) ... stack, in the out'ted variable ... Detach is called on a temporary CComPtr object ... The net effect is equivalent to CopyTo, ...
    (microsoft.public.vc.atl)
  • Re: current panics when Netgear WG511T ejected
    ... just one dhcp-assigned unicast addr. ... Even if you have no multicast addresses explicitly configured by yourself or any application, the multicast code is always used on any system configured with INET. ... Because the hardware is being ejected, the netinet part of the stack won't see the detach first, but net will, and this is where the panic is happening. ...
    (freebsd-current)
  • Re: Whats the secmantics of IoDetachDevice?
    ... C's driver will have its FastIoDetachDevice callback called, ... and should detach and destroy C in this callback. ... then A is sure to be removed from the stack. ...
    (microsoft.public.development.device.drivers)
  • Re: Serial Upper Filter Driver Help Required
    ... You need to shutdown the stack to detach the driver. ... Maxim Shatskih, Windows DDK MVP ...
    (microsoft.public.development.device.drivers)