I'm writing a C# COM dll that will be used by both Managed C# as well as Delphi and C++ programs and javascript. The COM dll includes a monitor part where the application registers a function that is supposed to return a string value to the dll. I have done this before for javascript 'applications' where you would simply pass a function as a parameter to the dll. When the dll needs to query the javascript 'application' the following is run:
Type t = theScript.GetType();
object ret = t.InvokeMember("", BindingFlags.InvokeMethod, null, theScript, new object[] { });
'theScript' is stored as an Object in the C# dll. As far as I understand this is accomplished by IDispatch. My theory now is that I should be able to use the same approach for the other languages. So I made a COM visible method with this signature:
void RegisterQuery(object method);
However I can't figure out how to pass a parameter to this method from C#. I've tried using a delegate but calling the delegate simply returns the ToString() method from the delegate (the one that returns the calss name). Nothing else that I have tried even compiles.
So I have two questions:
- How shall I pass a method parameter to this dll from C# so that the dll will be able to call the methods, in the manner specified above, when it needs to?
- Is this really IDispatch or is there another reason why it works for javascript?
Thanks in advance