How to declare and implement a COM interface on C# that inherits from another COM interface?

前端 未结 1 1358
野的像风
野的像风 2021-02-09 05:08

I\'m trying to understand what is the correct why to implement COM interfaces from C# code. It is straightforward when the interface doesn\'t inherit from other base interface.

1条回答
  •  太阳男子
    2021-02-09 05:36

    Neat trick with the new keyword, that would indeed fix the problem. The issue here is that COM doesn't support inheritance. It is merely notational convenience in IDL to make it look like it does. In reality, an interface v-table must aggregate all the "inherited" base interfaces. In other words, for the IPersistFolder interface it must replicate the v-table slots for the 3 IUnknown methods and the IPersist::GetClassID method. The CLR takes care of IUnknown btw.

    The v-table that .NET builds is not compatible with this layout, it doesn't replicate the base class method slots.

    0 讨论(0)
提交回复
热议问题