views:

68

answers:

1

According to this article about writing shell extensions in .Net, inheriting the shell interfaces as you might naturally do when writing code doesn't work. I've observed this in my own code as well.

Doesn't work:

public interface IPersist {
    // stuff specific only to IPersist
}

public interface IPersistFolder : IPersist {
    // stuff specific only to IPersistFolder
}

Does work:

public interface IPersistFolder {
    // stuff specific to IPersist only
    // stuff specific to IPersistFolder only
}

The article notes this fact:

Lo and behold, it worked! Notice that I've abandoned any idea that IPersistFolder is inherited from anything at all and just included the stubs from IPersist right in its definition. In all candor, I can't tell you why this is but it definitely works just fine and shouldn't give you any problems.

So my I'll ask the question this guy didn't know; why didn't the original code work?

+2  A: 

COM doesn't support inheritance. The COM interface declarations are defined in the SDK header files with inheritance, but they are intended to be parsed by a C++ compiler. It does support inheritance. The concrete implementation of the IPersistFile interface must provide an implementation of all methods, including those from IUnknown and IPersist. IUnknown is taken care of by the CLR.

Hans Passant