Board index » cppbuilder » Returning second interface pointer fromn the first interface in Automation object

Returning second interface pointer fromn the first interface in Automation object

In one of the methods of my primary interface for my automation object I
want to return the pointer to a secondary interface for the same object.
The client passes in a 'SecondaryInterface ** parm' as a parameter to my
primary interface pointer. Since both interfaces are implemented by the
same implementation class in ATL, is it safe to just pass the pointer
back as:

*parm = static_cast<SecondaryInterface *>(this);

or do I need to do a QueryInteface for the secondary interface ? In
either case do I need to do an AddRef() and does the client need to do a
Release() or is this all taken care of by ATL under the covers ?

 

Re:Returning second interface pointer fromn the first interface in Automation object


Quote
Edward Diener wrote:
> In one of the methods of my primary interface for my automation object I
> want to return the pointer to a secondary interface for the same object.
> The client passes in a 'SecondaryInterface ** parm' as a parameter to my
> primary interface pointer. Since both interfaces are implemented by the
> same implementation class in ATL, is it safe to just pass the pointer
> back as:

> *parm = static_cast<SecondaryInterface *>(this);

> or do I need to do a QueryInteface for the secondary interface ? In
> either case do I need to do an AddRef() and does the client need to do a
> Release() or is this all taken care of by ATL under the covers ?

MMmmmm... I was about to ask the same question ! Did you find an answer ?

--
Benoit St-Hilaire
  bsthi...@total.net

Re:Returning second interface pointer fromn the first interface in Automation object


Yes, I did. QueryInterface and AddRef is needed if going directly through the
interface object but only QueryInterface is needed if going through a smart
interface ( smart pointer or disp interface ) since these objects take care of
AddRef and Release on their own.
Quote
Benoit St-Hilaire wrote:
> Edward Diener wrote:

> > In one of the methods of my primary interface for my automation object I
> > want to return the pointer to a secondary interface for the same object.
> > The client passes in a 'SecondaryInterface ** parm' as a parameter to my
> > primary interface pointer. Since both interfaces are implemented by the
> > same implementation class in ATL, is it safe to just pass the pointer
> > back as:

> > *parm = static_cast<SecondaryInterface *>(this);

> > or do I need to do a QueryInteface for the secondary interface ? In
> > either case do I need to do an AddRef() and does the client need to do a
> > Release() or is this all taken care of by ATL under the covers ?

> MMmmmm... I was about to ask the same question ! Did you find an answer ?

> --
> Benoit St-Hilaire
>   bsthi...@total.net

Other Threads