Another Question on Aggregation 
Author Message
 Another Question on Aggregation

Hi,
I have a dual interface defined for the object that is going to be
aggregated from my atl control that will be used from VB.
The aggregatable component implements the IDispatch so that it can be used
from VB.
The problem is I cannot get the object from VB... is there a flaw in my
design.

Say I have 5 objects [controls] and each is going to use the agg.. object.
Does it make sense to aggregrate rather than contain the object ?

thanx Murtuza



Sun, 26 Oct 2003 22:59:08 GMT  
 Another Question on Aggregation
Are the controls themselves implementing IDispatch or any dual interface?
You cannot expose two implementations of IDispatch from one object, be it
through aggregation or containment or by any other means. There are
techniques for merging several dispinterfaces into one IDispatch
implementation though.
--
With best wishes,
    Igor Tandetnik


Quote:
> Hi,
> I have a dual interface defined for the object that is going to be
> aggregated from my atl control that will be used from VB.
> The aggregatable component implements the IDispatch so that it can be used
> from VB.
> The problem is I cannot get the object from VB... is there a flaw in my
> design.

> Say I have 5 objects [controls] and each is going to use the agg.. object.
> Does it make sense to aggregrate rather than contain the object ?

> thanx Murtuza



Mon, 27 Oct 2003 00:04:27 GMT  
 Another Question on Aggregation
Yes the controls implement the IDispatch.
You mentioned something abot techniques.....what are they?
Appreciate your help.
Thanx Murtuza


Quote:
> Are the controls themselves implementing IDispatch or any dual interface?
> You cannot expose two implementations of IDispatch from one object, be it
> through aggregation or containment or by any other means. There are
> techniques for merging several dispinterfaces into one IDispatch
> implementation though.
> --
> With best wishes,
>     Igor Tandetnik



> > Hi,
> > I have a dual interface defined for the object that is going to be
> > aggregated from my atl control that will be used from VB.
> > The aggregatable component implements the IDispatch so that it can be
used
> > from VB.
> > The problem is I cannot get the object from VB... is there a flaw in my
> > design.

> > Say I have 5 objects [controls] and each is going to use the agg..
object.
> > Does it make sense to aggregrate rather than contain the object ?

> > thanx Murtuza



Mon, 27 Oct 2003 01:31:31 GMT  
 Another Question on Aggregation
The easiest one is if dispinterfaces don't have conflicting DISPIDs. Then
you implement GetIdsOfNames and Invoke by simply trying one implementation
first, then if it returns an error (like DISP_E_MEMBERNOTFOUND) you forward
to another implementation.

If two dispinterfaces have conflicting DISPIDs, not all is lost. You pick a
constant that's larger than any DISPID the first interface uses (let's call
it DISPID_SEP). Then in GetIDsOfNames, if the first delegation succeeds, you
return DISPIDs as is. If the second succeeds, you add DISPID_SEP to all of
them. Then in Invoke, if DISPID is smaller than DISPID_SEP, you forward it
to the first implementation, otherwise you subtract DISPID_SEP and forward
to the second implementation.

Of course this doesn't work if both interfaces implement predefined DISPIDs,
like DISPID_VALUE or DISPID_BACKCOLOR. But then again, you have to choose
one implementation for BackColor property anyway.

This is good for GetIdsOfNames and Invoke methods and for scripting clients
that don't use type info. To implement GetTypeInfo, it is best to actually
describe the merged dispinterface in IDL (accounting for offset DISPIDs if
you plan to use method 2). Then you can use the stock implementation of
GetTypeInfo and GetTypeInfoCount (that of IDispatchImpl) and concentrate on
implementing GetIdsOfNames and Invoke.

Another way is to describe the merged interface as dual in IDL, have your
control implement it, implement some methods in the control itself and
forward the rest to the contained object.

None of the methods benefit from aggregation BTW, so I suggest you drop it.
--
With best wishes,
    Igor Tandetnik


Quote:
> Yes the controls implement the IDispatch.
> You mentioned something abot techniques.....what are they?
> Appreciate your help.
> Thanx Murtuza



> > Are the controls themselves implementing IDispatch or any dual
interface?
> > You cannot expose two implementations of IDispatch from one object, be
it
> > through aggregation or containment or by any other means. There are
> > techniques for merging several dispinterfaces into one IDispatch
> > implementation though.
> > --
> > With best wishes,
> >     Igor Tandetnik



> > > Hi,
> > > I have a dual interface defined for the object that is going to be
> > > aggregated from my atl control that will be used from VB.
> > > The aggregatable component implements the IDispatch so that it can be
> used
> > > from VB.
> > > The problem is I cannot get the object from VB... is there a flaw in
my
> > > design.

> > > Say I have 5 objects [controls] and each is going to use the agg..
> object.
> > > Does it make sense to aggregrate rather than contain the object ?

> > > thanx Murtuza



Mon, 27 Oct 2003 02:00:38 GMT  
 Another Question on Aggregation
Thanx for the extensive explanation.... Aggregation is OUT :-)

Murtuza


Quote:
> The easiest one is if dispinterfaces don't have conflicting DISPIDs. Then
> you implement GetIdsOfNames and Invoke by simply trying one implementation
> first, then if it returns an error (like DISP_E_MEMBERNOTFOUND) you
forward
> to another implementation.

> If two dispinterfaces have conflicting DISPIDs, not all is lost. You pick
a
> constant that's larger than any DISPID the first interface uses (let's
call
> it DISPID_SEP). Then in GetIDsOfNames, if the first delegation succeeds,
you
> return DISPIDs as is. If the second succeeds, you add DISPID_SEP to all of
> them. Then in Invoke, if DISPID is smaller than DISPID_SEP, you forward it
> to the first implementation, otherwise you subtract DISPID_SEP and forward
> to the second implementation.

> Of course this doesn't work if both interfaces implement predefined
DISPIDs,
> like DISPID_VALUE or DISPID_BACKCOLOR. But then again, you have to choose
> one implementation for BackColor property anyway.

> This is good for GetIdsOfNames and Invoke methods and for scripting
clients
> that don't use type info. To implement GetTypeInfo, it is best to actually
> describe the merged dispinterface in IDL (accounting for offset DISPIDs if
> you plan to use method 2). Then you can use the stock implementation of
> GetTypeInfo and GetTypeInfoCount (that of IDispatchImpl) and concentrate
on
> implementing GetIdsOfNames and Invoke.

> Another way is to describe the merged interface as dual in IDL, have your
> control implement it, implement some methods in the control itself and
> forward the rest to the contained object.

> None of the methods benefit from aggregation BTW, so I suggest you drop
it.
> --
> With best wishes,
>     Igor Tandetnik



> > Yes the controls implement the IDispatch.
> > You mentioned something abot techniques.....what are they?
> > Appreciate your help.
> > Thanx Murtuza



> > > Are the controls themselves implementing IDispatch or any dual
> interface?
> > > You cannot expose two implementations of IDispatch from one object, be
> it
> > > through aggregation or containment or by any other means. There are
> > > techniques for merging several dispinterfaces into one IDispatch
> > > implementation though.
> > > --
> > > With best wishes,
> > >     Igor Tandetnik



> > > > Hi,
> > > > I have a dual interface defined for the object that is going to be
> > > > aggregated from my atl control that will be used from VB.
> > > > The aggregatable component implements the IDispatch so that it can
be
> > used
> > > > from VB.
> > > > The problem is I cannot get the object from VB... is there a flaw in
> my
> > > > design.

> > > > Say I have 5 objects [controls] and each is going to use the agg..
> > object.
> > > > Does it make sense to aggregrate rather than contain the object ?

> > > > thanx Murtuza



Mon, 27 Oct 2003 21:15:21 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Question about aggregation using ATL and _com_ptr_t

2. Aggregation, RefCounting question????

3. Aggregation question???

4. atl 7.0 and attributed aggregation

5. OO Theory: Aggregation and Composition?

6. Object pooling and Aggregation

7. blind aggregation

8. IDL problem : setting Interface inside or outside typelib / Proxy stub vs Aggregation

9. Aggregation and connection points

10. aggregation and singletons

11. Aggregation

12. Aggregation/containment

 

 
Powered by phpBB® Forum Software