Re: Interface Question



<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


.



Relevant Pages

  • Re: 7.0 wishlist?
    ... The "auto-implement" is intended mainly for the odd situation where an existing class you can't edit fits some interface and you're willing to take responsibility for it if it turns out not to actually adhere to the contract, and try using it where that interface type is expected. ... If reference declarations started showing up with the odd asterisk, bang, or other punctuation mark on it, but never primitive declarations, people would probably be able to guess what was going on, on the basis of "what other binary flag might be set on references but not primitives and would be really useful besides can be/cannot be null?" ... the compiler cannot prove by static analysis that the RHS isn't null might be a good idea. ... Object foo, bar; ...
    (comp.lang.java.programmer)
  • Re: Anders Hejlsberg comment on immutable objects
    ... >explicit interface implementation exists is so an interface name can class ... Improper implicit conversions constitute a nasty ... >> With value types, the variable's value is the object, not a reference ... Consider the affects of our different views on a const ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: please try this program (generic resolution)
    ... of the specific interfaces of a generic interface that has that name and ... either is in the scoping unit in which the reference appears or is made ... And now in my example I misspelled ENISOC. ... external fun ...
    (comp.lang.fortran)
  • Re: C# Plugin system - same interface in two different assemblies...
    ... "add a reference to the appropriate assemblies to each and every project"? ... You don't have each plugin project deciding what ... its idea of the interface is. ... can't by forcing people to include them in assemblies as I've explained. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using early-bound interface on a late-bound object
    ... > the compiler determines which interfaces to use, ... > supports the declared interface. ... >> help if someone can point me to some authoritative document or reference ... within customer shops when they mirrored this 'division' to keep their ...
    (microsoft.public.vb.general.discussion)