0

I have a referenced a COM dll. Some methods expect a callback parameter. I checked the interop.MyComLib.dll in reflector:

public virtual extern void Foo([In, MarshalAs(UnmanagedType.IDispatch)] object pDispProgressCallBack);

How do I send this parameter? I can't send a delegate (compilation exception). I have tried sending this and received InvalidCastException.

2 Answers 2

1

IDispatch is a COM interface. The CLR will automatically implement it if you use [ComVisible(true)] and [ClassInterface(ClassInterfaceType.AutoDispatch)] attributes on your class. You can then pass an instance of the class and the cast will succeed. The code is then probably going to call some kind of method on that class so be sure that it is implemented. It isn't clear from the question what method that might be and what its signature should look like. It must exactly match, a mismatch is liable to prevent the callback from ever occurring without a diagnostic.

Sign up to request clarification or add additional context in comments.

Comments

0

You want to pass in an object that's an IDispatch and has a method with a DispId of 0. See this article for how to create an IDispatch, then give it a single method with DispId(0).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.