Sign in to follow this  
danromeo

[.net] Call Methods and Access Resources in a DLL Linked at Runtime

Recommended Posts

Hiya, once again thanks for reading this. WARNING: NEWBIE ALERT...I'm brand new to C#, but fairly experienced with C++. I have a dll which I am linking to at runtime. I've managed to load the dll file but I can't figure out how to call methods in the dll from the main program or to access resources which are imbedded in the dll. Help! Code thus far is as follows: Assembly assembly = Assembly.LoadFile(Environment.CurrentDirectory + "\\" + library); foreach (Type type in assembly.GetTypes()) { if (!type.IsClass || type.IsNotPublic) continue; Type[] interfaces = type.GetInterfaces(); object obj = Activator.CreateInstance(type); ... } Remember, be kind to newbies...And, thanks for the help.

Share this post


Link to post
Share on other sites
The topic you want to read up on is called 'Reflection', in the namespace System.Reflection. As I remember the general sort of thing you want to do is
type.Invoke(obj, BindingFlags.Method, "MethodName", new object[]{params})

... but I haven't actually used this stuff for a few months and don't have the docs on this computer, so that's almost certainly wrong in detail.

Read the .Net Help/MSDN examples, as I recall they're actually quite good on this subject.

(Edit: it was definitely wrong in detail since I missed a bracket ;D)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this