Re: MBV question #324: how to pass a MBV object in a VARIANT?
Jason S <firstname.lastname@example.org> wrote:
MVB will kick in when the client queries for any interface other than
IUnknown. If you want it to happen earlier, pack an IDispatch* into a
variant of type VT_DISPATCH.
how interesting! so it's like a jack-in-the-box which doesn't go off
right away. I take it the VARIANT marshals a proxy/stub pointer for
IUnknown doesn't require a proxy. Proxy manager on the client site knows
how to implement it. IUnknown is special this way.
Is this true only for marshalling something as a VARIANT, or is it
also true if you [out,retval] an IUnknown * as well? (seems like that
would be the case)
Is this documented somewhere?
It kind of follows. Marshalling decisions are made on per-interface
basis, not per-object. IUnknown is never marshalled.
That means if you have an object which
changes state periodically, that you want to marshal-by-value in a
VARIANT, the object itself has to support IDispatch* so it can be
marshalled as IDispatch *?
First, why would you ever want to marshal a mutable object by value?
This doesn't make much sense to me.
Second, your client will have to query for something other than IUnknown
before it can do any useful work with the object. If the client is
capable of querying for something other than IDispatch (in other words,
it's not a scripting client), why do you return via VARIANT anyway? Why
not just return [out, retval] IMyInterface** in the first place?
If on the other hand you need to support scripting clients that do
require an IDispatch, then of course your object would have to implement
Third, let's assume, for the sake of argument, that you do want to MBV a
mutable object, and you do want to hand it out as IUnknown*. Does it
really matter if the snapshot of the state is taken at the time the
method returns the object, or at the time said object is queried for the
With best wishes,
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