Hi,
We have .NET dlls containing interfaces that we want to use from COM. Each
interface has a Guid Attribute specifying its Interface ID. We use regasm in
order to generate the tlb and then use the DLL as COM #import statement in a
C++ project .
For some reason, when the tlb is generated, interface inheritance is not
applied to the generated IDL. For example, if we have two interfaces:
<C# Code Class Lib>
namespace Foo
{
[
System.Runtime.InteropServices.Guid("C5DDC244-4CFC-4f15-821B-787F9C0684D5")
]
public interface A
{
string FirstName{get;}
}
[
System.Runtime.InteropServices.Guid("97286132-A545-4965-9BE3-AC3E2C63ED9E")
]
public interface B : A
{
string LastName{get;}
}
}
<C# Code Class Lib/>
The generated IDL in the type lib will not show the inheritance :
<Generated IDL from TLB>
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: <could not determine filename>
[
uuid(89C9460C-048D-3C45-916C-8032C40350AB),
version(1.0),
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, ClassLibrary1,
Version=1.0.1642.16217, Culture=neutral, PublicKeyToken=null)
]
library ClassLibrary1
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface A;
interface B;
[
odl,
uuid(C5DDC244-4CFC-4F15-821B-787F9C0684D5),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Foo.A)
]
interface A : IDispatch {
[id(0x60020000), propget]
HRESULT FirstName([out, retval] BSTR* pRetVal);
};
[
odl,
uuid(97286132-A545-4965-9BE3-AC3E2C63ED9E),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Foo.B)
]
interface B : IDispatch {
[id(0x60020000), propget]
HRESULT LastName([out, retval] BSTR* pRetVal);
};
};
<Generated IDL from TLB/>
Is there a way to have interface B derived from interface A in the IDL?
What is the proper way to have the inheritance reflected in the tlb file?
Thanks,
Eric
Ken Kolda - 30 Jun 2004 16:48 GMT
I don't know of any way to work around this behavior, but you may also want
to consider the advantages this gives. If .NET were to automatically
generate a combined interface in the typelib, you would be prevented from
ever adding methods to the base interface without breaking existing clients.
That's because .NET would (most likely) construct the typelib interface by
appending the derived interface's methods onto the end of the base
interface. So if a new base interface method were added, all of the derived
methods would shift down a position in typelib's interface definition,
effectively breaking binary compatibility. You'd have to change all your
IIDs and recompile all your COM clients against the new typelib in order to
make them work again.
So, my suggestion is to simply replicate the same method signatures in your
derived interface. It's annoying in its redundancy, but may pay off in the
end.
Ken
> Hi,
>
[quoted text clipped - 13 lines]
>
> [
System.Runtime.InteropServices.Guid("C5DDC244-4CFC-4f15-821B-787F9C0684D5")
> ]
>
[quoted text clipped - 7 lines]
>
> [
System.Runtime.InteropServices.Guid("97286132-A545-4965-9BE3-AC3E2C63ED9E")
> ]
>
[quoted text clipped - 104 lines]
>
> Eric
Patrick Steele [MVP] - 30 Jun 2004 19:38 GMT
> Is there a way to have interface B derived from interface A in the IDL?
Unfortunately not. See:
http://tinyurl.com/36c5l
In the section "Interface Types"
"All exported interfaces extend directly from either IUnknown or
IDispatch, regardless of their inheritance hierarchy in managed code."

Signature
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele