Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# derived interface cannot work properly in C++

I have two interfaces defined in C#, as below:

[Guid("4938540B-3DB2-452c-A061-59EC499657E7")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IRADevice
{
   Void FA();
}

/// <summary>
/// IRADevice interface represents a given RADevice.
/// </summary>
[Guid("4938540B-3DB2-452c-A061-59EC499657E8")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IRADevice2 : IRADevice
{
    void FB();
}

In c++ code, I import the tlb produced by above interface using following command

#import "device.tlb"  raw_interfaces_only

The created tlh file is as below:

struct __declspec(uuid("4938540b-3db2-452c-a061-59ec499657e7"))
IRADevice : IDispatch
{
//
// Raw methods provided by interface
//

virtual HRESULT __stdcall FA ( ) = 0;
};

struct __declspec(uuid("4938540b-3db2-452c-a061-59ec499657e8"))
IRADevice2 : IDispatch
{
//
// Raw methods provided by interface
//

virtual HRESULT __stdcall FB ( ) = 0;
};

I expect IRADevice derives from IRADevice not from IDispatch, and includes FA function. Can anybody tell me where I did wrong?

like image 550
Dennis Lu Avatar asked Nov 04 '22 16:11

Dennis Lu


1 Answers

As @HansPassant stated this is a known limitation. It took me a minute but I found some relevant documentation to support that fact. http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx

The most relevant portion being:

COM interfaces declared in C# must include declarations for all members of their base interfaces with the exception of members of IUnknown and IDispatch — the .NET Framework automatically adds these. COM interfaces which derive from IDispatch must be marked with the InterfaceType attribute.

like image 192
Sacrilege Avatar answered Nov 12 '22 20:11

Sacrilege