C# how to implement IDispatch Interface?

228 views Asked by At

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?

1

There are 1 answers

0
Charlieface On

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

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