Re: Interface Question
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 9 Oct 2006 14:24:05 +0200
<alanglloyd@xxxxxxx> wrote in message
news:1160386781.998311.103960@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
Now IShellLink has _none_ of the methods of IPersist or IPersistFile,
so _how_ can an IShellLink be typecast to an IPersistFile.
The actual object may implement both the (disjoint) lists.
They are not totally disjoint, by the way. Both include the methods
inherited from IUnknown. It's like Destroy; every object can be
Destroyed because they're all TObjects. All interfaces can be cast
to other interfaces because they all include IUnknown.QueryInterface.
Or is the
COM object of ObjectIF somehow re-created as an IPersistFile when
type-cast as such.
The object is never re-created. If I understand correctly, an interface
reference points to a VMT-like structure that includes the methods
prescribed by the interface. A classtype that implements multiple
interfaces simply builds several such tables from its 'master' VMT.
There's probably more to it as a reference through an interface type
must still be able to access the instance's fields, but this at least
explains some of it for me.
It is an artefact of COM and its identification of interfaces through
GUIDs that a classtype declared to inherit a derived interface type is
not automatically recognised to also implement any ancestor interface.
Since querying for the same interface must always return the same pointer
for any given object, it follows that an IUnknown reference to that COM
object can't be the same as the ShellLink reference to it; using the
IPersist reference for the IUnknown reference would be equally valid
and therefore invalid (reliably choosing one might solve this problem
but not gain anything over dedicated pointers). Whatever the reasoning,
the upshot is that any (supported) interface reference queried from an
object is going to be different from the classtype reference and from all
the other interface references.
You _can_ compare interface references, but you have to downcast them all
to IUnknown first.
Groetjes,
Maarten Wiltink
.
- Follow-Ups:
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- From: alanglloyd@xxxxxxx
- Re: Interface Question
- References:
- Interface Question
- From: alanglloyd@xxxxxxx
- Interface Question
- Prev by Date: Re: Interface Question
- Next by Date: Re: Interface Question
- Previous by thread: Re: Interface Question
- Next by thread: Re: Interface Question
- Index(es):
Relevant Pages
|