Question

In IVsHierarchy interface for Visual Studio packages, there are methods Unused0, Unused1, Unused2, Unused3 and Unused4 with the following description:

Adds new methods without recompiling or breaking binary compatibility.

Can someone explain this in more detail. How do these methods help exactly?

Was it helpful?

Solution

The Visual Studio extension objects are implemented in COM. One hard rule in COM is that interfaces are immutable. Changing an interface requires re-assigning the interface IID. A guid that identifies the interface. That causes lots of pain to anybody that uses the interface. They'll have to alter their code and recompile it.

This immutability requirement exists because under the hood COM interfaces are implemented as a table of method addresses. Disaster strikes when there's a mismatch between what the client code assumes the table looks like and the actual table as implemented by the server. Or in other words, when the interfaces are not binary compatible. That produces very hard to diagnose runtime errors, triggered when the client code ends up calling the wrong method or uses a table slot that doesn't have an associated method at all. This is the infamous COM DLL Hell problem. Changing the IID solves it, the client code simply won't be able to find the old implementation anymore. Still a nasty error but at least easy to diagnose.

The place holders are there to allow Microsoft to add new methods to the interface but not break the table layout. And thus won't have to rename the interface and reassign the interface IID. And thus won't force addin vendors to recompile their addins. Unless a new addin tries to use the old interface implementation, that still won't work. But with odds for a decent exception message instead of a nasty AccessViolation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top