1

I've got a CoClass that is describes as below:

[
    uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), 
    version(1.0), 
    helpstring("FooBar")
]
coclass FooBar
{
    [default] interface IFoo;
    interface IBar;
}

So my questions are:

  1. Why does tlbimp only expose the IFoo interface, while oleview.exe shows both interfaces?
  2. Does tlbimp only expose [default] interfaces and why? (According to the MSDN [default] "is intended for use by macro languages.")
  3. How can I model this case in MIDL/COM? Should I use association instead of inheritance?
VividD
  • 10,456
  • 6
  • 64
  • 111
Carsten
  • 11,287
  • 7
  • 39
  • 62
  • If you declare your interfaces in either the same idl-file or import the interfaces from another idl-file, your object can expose as many interfaces as desired. After obtaining an object with CoCreateInstance() you need to use QueryInterface() to obtain your desired interface. Have look [here](http://msdn.microsoft.com/en-us/library/ms680573(VS.85).aspx) and consider the reference, too. And about [MIDL](http://msdn.microsoft.com/en-us/library/aa367091(v=vs.85).aspx) there are some examples, too. – bash.d Feb 08 '13 at 09:45
  • Thanks for your comment. I know that I can access the interfaces through `QueryInterface()`, but my question concerns the RCW's that get generated from `tlbimp` and accessed by .NET clients. I am not able to call `QueryInterface` in .NET 2.0 (I guess it was introduced with .NET 4.0, but this is not an option atm). – Carsten Feb 08 '13 at 09:53
  • The CLR automatically calls QueryInterface, just cast the object to the interface type. – Hans Passant Feb 21 '13 at 15:25
  • @HansPassant: Thanks! :) But couldn't the InterOp automatically `QueryInterface` whenever I call `IBar.Something()` like `new FooBar().Something()` (without casting it explicitly to IBar)? What I do not understand is why the interop does not inherit the CoClass from all interfaces... this would simplify client development, since I can see all members of all interfaces with IntelliSense. I would accept an answer that substantiates that decision. :) – Carsten Feb 22 '13 at 07:56

0 Answers0