Importing a basic type library using the tlbimp.exe
tool allways creates an interface for each coclass
. For example this IDL-description
interface IFoo : IUnknown
{
HRESULT DoSomething();
}
coclass Bar
{
[default] interface IFoo;
}
results in:
- an interface
IFoo
as a representation of the COM interface, - a class
BarClass
as a representation of the COM coclass and - an interface
Bar
, annotated with theCoClassAttribute
.
Where the GUIDs of Bar
and IFoo
are equal. The MSDN states on this topic:
This interface has the same IID as the default interface for the coclass. With this interface, clients can always register as event sinks.
That's the only thing I found on this topic. I know that, due the CoClassAttribute
, I can use the interface to create instances of the actual class. I also know that (practically) I can simply use BarClass
to create a new instance of the class. What I don't understand is, why the import process generates the Bar
interface, even if the coclass
does not define an event source and thus no event sink can be connected to it.
Would it be possible to remove the Bar
interface 1 in this example or are there some other risks, I have not yet considered?
1 For example by disassembling the interop assembly.