calling a delegate in a late bound C# dll

D

Daniel

How do I call a delegate in late bound C# dll? there some way to do this w/
a sharedinterface file? any examples? i tried this but it doesnt work:

(oType.GetMethod("IOCTLJOB").Invoke(pObj, new object[] {
pClass1.m_job } )).ToString();

and it returns the error:

Additional information: Object type cannot be converted to target type.

I have the delegate defined in both the late bound dll and the host assembly
like this:
public delegate void Job();
 
C

cecil

Daniel,
A delegate is not a method so GetMethod does will not work. In the
late bound dll what is IOCTLJOB? Where did you get oType from? Show
some code from both dll's and I can probably help you. From your
question I am still not sure what you are trying to accomplish.

PS if you need to have a void delegate with no args then the framwork
defines MethodInvoker so no need to create your own class.
Cecil Howell MCSD, MCAD.Net, MCT
 
M

Mr. Mountain

Here's one way to do it:

protected void PerformAction(string delegateMethodName)
{
MyDelegate targetAction = Delegate.CreateDelegate(typeof(MyDelegate), this,
delegateMethodName) as MyDelegate;
...
}

((MyDelegate)(targetAction.Method)).Invoke(this, new object[] {
myParameter } );


I didn't actually compile the code, but it should be pretty close.

Hope that helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top