lundi 29 septembre 2014

C# COM Interface Inheritance


Vote count:

0




I have the following (DirectShow related) COM interface in C++ that I need to call in C#.



[uuid("...")] : public IUnknown
interface IBar
{
STDMETHOD(Bar)(void);
}

[uuid("...")]
interface IFoo : public IBar
{
STDMETHOD(Foo)(void);
}


I declared this in C# as the following but it crashes out with Access Violation when IFoo.Foo() is called. Works fine with IBar.Bar() is called though. What is the correct way to write the equivalent interface in C#?



[ComImport, Guid("...)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[SuppressUnmanagedCodeSecurity]
public interface IBar
{
[PreserveSig] void Bar(); // Calling this is OK
}

[ComImport, Guid("...)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[SuppressUnmanagedCodeSecurity]
public interface IFoo : IBar
{
[PreserveSig] void Foo(); // Calling this crashes
}


The vtables must be incompatible in C# vs C++ for inherited COM interface. Is there a way to tell C# to adhere to the C++ declaration?



asked 25 secs ago

Zach Saw

1,876






C# COM Interface Inheritance

Aucun commentaire:

Enregistrer un commentaire