Re: Default interface
nly <nlyee2001@yahoo.com> wrote:
The importance of a default interface in COM is that of all the
interfaces a class may implement, only the default interface supports
late binding.
Incorrect. An IDispatch implementation supports late binding, whether
declared as default or not. It is possible to implement a dispinterface
and a custom interface on the same object, and declare the latter to be
default (though admittedly it's not clear why anybody would want to do
that).
And since scripting clients like VBScript only do late
binding, the methods on the default interface are the only ones they
can see.
Scripting clients like VBScript don't read type libraries and thus could
not care less which interface is marked [default]. They just QI for
IDispatch and proceed from there.
Understand that, when you mark an interface as [default] in coclass
declaration, all it does is set a flag in the type library. There are no
other implications. Some clients read the type library and assign
meaning to this flag. Other clients don't read the type library, or read
it but ignore this flag.
For an example of a client that interprets [default] flag, VB allows one
to use coclass name wherever this coclass' default interface name can
appear. This is convenient in the common case where a coclass implements
just one interface, marked [default].
1. Is there always a default interface in a component?
No.
2. Can this default interface be either derived from IUnknown or
IDispatch?
Every interface is ultimately derived from IUnknown. An interface marked
[default] may or may not derive from IDispatch. It may also be a
dispinterface (which is an incarnation of IDispatch and cannot be said
to *derive* from IDispatch).
3. Is the above statement true for both cases in 2?
The statement above is numbered 2. You are asking whether a statement is
true with respect to itself. I don't quite understand this question.
--
With best wishes,
Igor Tandetnik
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