2

I have known that a class like blow will auto implement IDispatch interface:

[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Test
{
}

Now my need is to override the Invoke function, how can I do this?

Supplement: I have a class Test and then I want to make a wrapper to make the Test seems has more function:

[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class TestWrapper
{
    public void NewFunc()
    {
    }
    private Test _test;
}

I cannot make TestWrapper to inherit from Test class, so I need override the IDispatch.GetIDsOfNames to expose test's interface. How can I do this?

wohlstad
  • 12,661
  • 10
  • 26
  • 39
yunate
  • 59
  • 3
  • I have try use `[ClassInterface(ClassInterfaceType.None)]` and then make TestWrapper inherit from IDispatch`public class TestWrapper : IDispatch` and then override each interface of IDispatch, but it cannot work. – yunate Mar 16 '23 at 10:15
  • `ComVisible` by default implements `IDispatch` unless you use `InterfaceTypeAttribute` with `InterfaceIsIUnknown` see also https://stackoverflow.com/q/66634482/14868997 – Charlieface Mar 16 '23 at 10:28

1 Answers1

0

ComVisible by default implements IDispatch anyway, unless you use InterfaceTypeAttribute with InterfaceIsIUnknown.

So there is no need for anything special to get IDispatch functionality.

Charlieface
  • 52,284
  • 6
  • 19
  • 43