Dynamic aggregation sort-of 
Author Message
 Dynamic aggregation sort-of

Basically I want to be able to blindly aggregate an inner object that is
created before the outer object.

The outer object implements a method that simply lets me set the inner
object.  After I set the inner object, I would like all of its interfaces to
be exposed from the outer object.  However, there is no way to set the
controlling unknown since I am creating the outer object after the inner
object.

Any help will be appreciated.

Thanks,

Jeffrey



Tue, 01 Mar 2005 10:03:00 GMT  
 Dynamic aggregation sort-of
Impossible.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Basically I want to be able to blindly aggregate an inner object that is
> created before the outer object.

> The outer object implements a method that simply lets me set the inner
> object.  After I set the inner object, I would like all of its interfaces to
> be exposed from the outer object.  However, there is no way to set the
> controlling unknown since I am creating the outer object after the inner
> object.

> Any help will be appreciated.

> Thanks,

> Jeffrey



Wed, 02 Mar 2005 01:34:47 GMT  
 Dynamic aggregation sort-of
Maybe you can do something like this with Universal Delegator - see

http://www.develop.com/kbrown/com/samples.htm

You'll need to hook and handle all calls to QI, AddRef and Release on
any of the wrapped object's interfaces.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Basically I want to be able to blindly aggregate an inner object that
is
> created before the outer object.

> The outer object implements a method that simply lets me set the inner
> object.  After I set the inner object, I would like all of its
interfaces to
> be exposed from the outer object.  However, there is no way to set the
> controlling unknown since I am creating the outer object after the
inner
> object.

> Any help will be appreciated.

> Thanks,

> Jeffrey



Wed, 02 Mar 2005 04:38:30 GMT  
 Dynamic aggregation sort-of
Igor, that's impossible! The trick to aggregation is that the inner
object knows about the outer unknown upon creation. All that
can be done using the Universal Delegator is, well... delegation...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Maybe you can do something like this with Universal Delegator - see

> http://www.develop.com/kbrown/com/samples.htm

> You'll need to hook and handle all calls to QI, AddRef and Release on
> any of the wrapped object's interfaces.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Basically I want to be able to blindly aggregate an inner object that
> is
> > created before the outer object.

> > The outer object implements a method that simply lets me set the inner
> > object.  After I set the inner object, I would like all of its
> interfaces to
> > be exposed from the outer object.  However, there is no way to set the
> > controlling unknown since I am creating the outer object after the
> inner
> > object.

> > Any help will be appreciated.

> > Thanks,

> > Jeffrey



Wed, 02 Mar 2005 06:28:38 GMT  
 Dynamic aggregation sort-of
True aggregation is of course impossible, but I'm thinking about
"sort-of" aggregation, which is all the OP is asking for. Inner object
needs to know about outer object to defer IUnknown methods to it. If I
manage to wrap every interface pointer originating from the inner object
into a delegator, intercept all calls to IUnknown methods and implement
them appropriately, I could simulate aggregation without changing inner
object, right? Universal Delegator does not just delegate, it also can
run hooks on every method call.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Igor, that's impossible! The trick to aggregation is that the inner
object knows about the outer unknown upon creation. All that
can be done using the Universal Delegator is, well... delegation...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Maybe you can do something like this with Universal Delegator - see

> http://www.develop.com/kbrown/com/samples.htm

> You'll need to hook and handle all calls to QI, AddRef and Release on
> any of the wrapped object's interfaces.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Basically I want to be able to blindly aggregate an inner object
that
> is
> > created before the outer object.

> > The outer object implements a method that simply lets me set the
inner
> > object.  After I set the inner object, I would like all of its
> interfaces to
> > be exposed from the outer object.  However, there is no way to set
the
> > controlling unknown since I am creating the outer object after the
> inner
> > object.

> > Any help will be appreciated.

> > Thanks,

> > Jeffrey



Wed, 02 Mar 2005 07:05:52 GMT  
 Dynamic aggregation sort-of
Thanks for the help.

I was able to actually override the InternalQueryInterface function in my
class to accomplish what I needed to accomplish.  Basically my
InternalQueryInterface just calls the CComObjectRootEx
InternalQueryInterface.  If it returns E_NOINTERFACE, then I call
QueryInterface on the inner unknown.  Of course, if I call QueryInterface
off of the returned Interface I will only be querying the inner Unknown.
This seems to work with the code that I am using, because the code that will
be using this will only QueryInterface from the Wrapped Unknown.  Do you see
anything wrong with this approach?  Thanks!

Jeffrey



Wed, 02 Mar 2005 07:53:27 GMT  
 Dynamic aggregation sort-of

Impossible.

That is what I thought.  I found a way around it though.

Thanks,

Jeffrey



Wed, 02 Mar 2005 07:54:54 GMT  
 Dynamic aggregation sort-of
The classic broken object identity. Once in the inner object,
you can't access the outer object at all. QI for IUnknown on
an interface in the inner object is different from the result
you get from QI for IUnknown on an interface of the outer
object. Most core COM rules broken - this is NOT a COM object
anymore!

What Igor was suggesting is to do true intercepted delegation
using Keith Brown's Universal Delegator. It has nothing to do
with aggregation really, although you get the same effect as
if doing blind aggregation. The price is an additional machine
jump instruction in the delegator - negligible compared to
regular delegation. The memory price is 4K per interface
vtable (1K method slots IIRC).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Thanks for the help.

> I was able to actually override the InternalQueryInterface function in my
> class to accomplish what I needed to accomplish.  Basically my
> InternalQueryInterface just calls the CComObjectRootEx
> InternalQueryInterface.  If it returns E_NOINTERFACE, then I call
> QueryInterface on the inner unknown.  Of course, if I call QueryInterface
> off of the returned Interface I will only be querying the inner Unknown.
> This seems to work with the code that I am using, because the code that will
> be using this will only QueryInterface from the Wrapped Unknown.  Do you see
> anything wrong with this approach?  Thanks!

> Jeffrey



Wed, 02 Mar 2005 09:27:03 GMT  
 Dynamic aggregation sort-of
For this to work the "Universal Delegator", do I need to know what
interfaces an object supports at compile time.  If I don't then this should
work.  I fortunately won't have to be writing these wrappers :),  I just
need to know its possible and to be able to document how it can be
accomplished.

I did know that there was at least two problems that could occur with my
approach.  The most obvious is the object identity problem.  (I know that I
am breaking a COM rule.)  What kind of "real" problems could this lead to?
It is well known that once an interface pointer is passed back from the
inner unknown, that any queryinterface will be on the inner object.
Currently the wrapper object is guaranteed to be run in-process so there
should not be any marshalling issues.   My approach seemed to work for what
I wanted it to do.

The second rule that I break and I don't see a way around it is that
QueryInterface can give back E_NOINTERFACE if I have not set the inner
object for an interface that I support if the inner object is set.  This is
really not a problem since callers of the wrapper will always set the inner
unknown before I get any interface other than IUnknown.

Are there some other major rules that I am breaking?

Perhaps a better solution on my part would be to add a method to the set
inner object such that I can get the inner object.  Then I could do
delegation if necessary on a few interfaces that I know and get the inner
unknown to pass to procedures that use some of the interfaces that does not
need to be implemented on the outer object.  I think that solution wouldn't
break any COM rules, but would require some extra logic to determine between
wrapped and non-wrapped objects.


The classic broken object identity. Once in the inner object,
you can't access the outer object at all. QI for IUnknown on
an interface in the inner object is different from the result
you get from QI for IUnknown on an interface of the outer
object. Most core COM rules broken - this is NOT a COM object
anymore!

What Igor was suggesting is to do true intercepted delegation
using Keith Brown's Universal Delegator. It has nothing to do
with aggregation really, although you get the same effect as
if doing blind aggregation. The price is an additional machine
jump instruction in the delegator - negligible compared to
regular delegation. The memory price is 4K per interface
vtable (1K method slots IIRC).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Thanks for the help.

> I was able to actually override the InternalQueryInterface function in my
> class to accomplish what I needed to accomplish.  Basically my
> InternalQueryInterface just calls the CComObjectRootEx
> InternalQueryInterface.  If it returns E_NOINTERFACE, then I call
> QueryInterface on the inner unknown.  Of course, if I call QueryInterface
> off of the returned Interface I will only be querying the inner Unknown.
> This seems to work with the code that I am using, because the code that
will
> be using this will only QueryInterface from the Wrapped Unknown.  Do you
see
> anything wrong with this approach?  Thanks!

> Jeffrey



Wed, 02 Mar 2005 13:30:34 GMT  
 Dynamic aggregation sort-of
I begin to highly dobt you need even delegation. Why not simply
return the inner object via a R/O property of the outer object and
keep them as two separate objects? I think I already answered
your question - you cannot aggreagate after the fact. The alternative
is delegation and the Universal Delegator can implement blind
delegation.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> For this to work the "Universal Delegator", do I need to know what
> interfaces an object supports at compile time.  If I don't then this should
> work.  I fortunately won't have to be writing these wrappers :),  I just
> need to know its possible and to be able to document how it can be
> accomplished.

> I did know that there was at least two problems that could occur with my
> approach.  The most obvious is the object identity problem.  (I know that I
> am breaking a COM rule.)  What kind of "real" problems could this lead to?
> It is well known that once an interface pointer is passed back from the
> inner unknown, that any queryinterface will be on the inner object.
> Currently the wrapper object is guaranteed to be run in-process so there
> should not be any marshalling issues.   My approach seemed to work for what
> I wanted it to do.

> The second rule that I break and I don't see a way around it is that
> QueryInterface can give back E_NOINTERFACE if I have not set the inner
> object for an interface that I support if the inner object is set.  This is
> really not a problem since callers of the wrapper will always set the inner
> unknown before I get any interface other than IUnknown.

> Are there some other major rules that I am breaking?

> Perhaps a better solution on my part would be to add a method to the set
> inner object such that I can get the inner object.  Then I could do
> delegation if necessary on a few interfaces that I know and get the inner
> unknown to pass to procedures that use some of the interfaces that does not
> need to be implemented on the outer object.  I think that solution wouldn't
> break any COM rules, but would require some extra logic to determine between
> wrapped and non-wrapped objects.



> The classic broken object identity. Once in the inner object,
> you can't access the outer object at all. QI for IUnknown on
> an interface in the inner object is different from the result
> you get from QI for IUnknown on an interface of the outer
> object. Most core COM rules broken - this is NOT a COM object
> anymore!

> What Igor was suggesting is to do true intercepted delegation
> using Keith Brown's Universal Delegator. It has nothing to do
> with aggregation really, although you get the same effect as
> if doing blind aggregation. The price is an additional machine
> jump instruction in the delegator - negligible compared to
> regular delegation. The memory price is 4K per interface
> vtable (1K method slots IIRC).

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Thanks for the help.

> > I was able to actually override the InternalQueryInterface function in my
> > class to accomplish what I needed to accomplish.  Basically my
> > InternalQueryInterface just calls the CComObjectRootEx
> > InternalQueryInterface.  If it returns E_NOINTERFACE, then I call
> > QueryInterface on the inner unknown.  Of course, if I call QueryInterface
> > off of the returned Interface I will only be querying the inner Unknown.
> > This seems to work with the code that I am using, because the code that
> will
> > be using this will only QueryInterface from the Wrapped Unknown.  Do you
> see
> > anything wrong with this approach?  Thanks!

> > Jeffrey



Sat, 05 Mar 2005 02:08:19 GMT  
 Dynamic aggregation sort-of
The Universal Delegator is cool!!! I was having problems seeing how this
would work until I took a look at the code.

The property solution would almost work.  (It would be better than my other
solution by a long shot).  However, I think the UD will actually be better
because it allows for some additional enhancements that would not be
possible with the property method.  In the code I am dealing with, I could
set and get the inner object as I needed.  The only problem with this is
that the majority of objects will not be wrapped and I will have to
QueryInterface on each one of these to see if they are wrapped or not.  (Or
I could store a boolean or something, but it still takes a little more
logic).  However, I call some functions that use the original object
presently (and soon will use either).  It would be nice for them to be able
to use the wrapped object.

Your help has been greatly appreciated.  Thanks!

Jeffrey



Sat, 05 Mar 2005 06:57:18 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Dynamic linking (sort of) question

2. Sorting routine for dynamic 2-d array

3. CListCtrl: Sort of an ListControl with Dynamic created Columns

4. Fast sorting (sort of)

5. Quick sort vs. bubble sort

6. DefaulView.Sort enumerating rows not sorted????

7. sort algorithm for simple sort

8. almost sorted Quick Sort

9. Merge Sort and Quick Sort comparison

10. Selection Sort & Merge Sort

11. Ann: Sorting and Merging with Sort Solution ActiveX

12. CListCtrl: Sorting by Column: Sort function failure

 

 
Powered by phpBB® Forum Software