I know what your getting at, but it is not correct to say that you can not
up-cast to IDispatch on a dual.  They are in fact type compatible and there
is no danger in assigning a ref of type ISearch to IDispatch when ISearch is
a dual.  Even though it may not be the same VPtr returned when you QI for
IDispatch, but that does not mean that it is not type compatible with
IDispatch.

It is of course illegal to down cast for the reasons mentioned.

Russ

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Peter Ritchie
Sent: Tuesday, March 07, 2006 3:36 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Safe to modify IDL to change from IDispatch
to a different Interface?

>An object that implements a dual interface is not required to return
>the same vptr when QIed for IDispatch that it returns when it is QIed
>for its dual interface. It can, and often will because that's usually
>the easiest thing to do, but it's not actually obliged to.

Indeed.  QI can do whatever it needs to do; that's what it's for (to support
aggregation, for example).  Dual interfaces are expected
(required?) to have a specific VTBL format.  If IServer implements MethodX
() and defines itself as dual-interface there must be 8 entries in the VTBL,
the IDispatch members and MethodX().

The problem is, from a COM interface point of view, you don't know if an
interface you're calling QI on is actually a dual-interface; so you can't be
sure a simple cast to/from IDispatch is safe.  Proxies are the prime
example.

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to