Hey all, so I'm looking for a way to call a method in an application externally from a dll. (see example below) This is what I'm trying however it's a) not working and b) if it was working i have a feeling that calling DynamicInvoke is going to be painfully slow.

first all if I did want to do it this way how do I deal with returns types as currently this will errors saying callthisexternally() has wrong return type.

is there a better way to do this?

--- within a a dll ---
public class mydll
{
    // etc.. blah blah

    public object callfromdll(string commandName, int requiredArgs, Delegate method)
    {
        // do stuff

        // now invoke the method
        return method.DynamicInvoke(method.Method.GetParameters().Select(p => p.ParameterType).ToArray());
    }


}

-- within an application that's refrancing the above dll --
public someclass
{
    // etc.. stuff here
    mydll m = new mydll();
    m.callfromdll("callthisexternally", 0, new Action(callthisexternally));


    // the function to be called externally
    public string callthisexternally()
    {
        // do stuff
        return "i was called!";
    }
}

Recommended Answers

All 2 Replies

why dont you go for adding refference of your dll from solution expolrer

Are you trying to call a managed library or a native library?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.