You have the wrong names, which does not help to understand what is happening. The Bar component in the type library generates the Bar interface and the BarClass class, there is no "FooBar".
This is just an extra glue that type library automatically generates to make porting code simpler. Especially important for VB6 code, it required more freedoms with the COM object model. VB6 uses a class as if it were a real implementation class. There is no such thing in COM; a class is an opaque place for a class; these are interfaces that do all the work. VB6 never supported the concept of interfaces, so direct COM modeling in code was not possible.
The VB6 compiler itself generates a code class from the Class keyword in the code and generates an interface that contains the actual methods and properties. This interface is hidden, it has the same class name, but with a leading underscore. By convention, this causes object browsers to hide the interface. This way your Bar style, written in VB6, will generate the _Bar interface.
Thus, the converted VB6 program will use Bar everywhere. This will not compile unless Bar is replaced by IFoo. The synthesized Bar interface comes to the rescue, avoiding the need for it.
It remains to solve two problems fixed by the synthetic BarClass type. New Bar() will not compile because instantiating an interface is not legal. The compiler solves this problem; it automatically replaces "Bar" with "BarClass". What is the actual role of the [CoClass] attribute, it provides a name for the class associated with the interface. And events are a problem, they are implemented in COM using the dispinterface. Again, a separate interface with an intricate mechanism under the hood that signs events (IConnectionPoint, etc.). The synthetic BarClass makes them realistic. NET events.
source share