Dynamic Library loading..

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

I will have the path of a DLL i.e C:\Test\Test.dll and a Method name in the
DLL say ExecuteMe(string arg1, int arg2). I want to be able to load the DLL
at run-time and execute this method. I also want to be able to capture the
return value of the Method.

Vijay
 
Vijay,

Is this an unmanaged DLL that exports a C type function, or is it a
managed DLL? The ways you would do this are very, very different.
 
Nicholas, it can be both, for now I would like to know only for managed
DLL's

Vijay

Nicholas Paldino said:
Vijay,

Is this an unmanaged DLL that exports a C type function, or is it a
managed DLL? The ways you would do this are very, very different.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VJ said:
I will have the path of a DLL i.e C:\Test\Test.dll and a Method name in
the DLL say ExecuteMe(string arg1, int arg2). I want to be able to load
the DLL at run-time and execute this method. I also want to be able to
capture the return value of the Method.

Vijay
 
VJ,

For managed DLL's, you would use reflection (assuming that the types you
are loading don't implement a common interface which you have access to).
You would get the Type instance, and from there, you can get method/property
information, from which you can get the value or invoke the method.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VJ said:
Nicholas, it can be both, for now I would like to know only for managed
DLL's

Vijay

Nicholas Paldino said:
Vijay,

Is this an unmanaged DLL that exports a C type function, or is it a
managed DLL? The ways you would do this are very, very different.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VJ said:
I will have the path of a DLL i.e C:\Test\Test.dll and a Method name in
the DLL say ExecuteMe(string arg1, int arg2). I want to be able to load
the DLL at run-time and execute this method. I also want to be able to
capture the return value of the Method.

Vijay
 
Vijay,

First of all you should load the assembly and get a reference to it, take a
look at:

http://msdn.microsoft.com/library/d...lrfSystemReflectionAssemblyClassLoadTopic.asp

Regards - Octavio

VJ said:
Nicholas, it can be both, for now I would like to know only for managed
DLL's

Vijay

Nicholas Paldino said:
Vijay,

Is this an unmanaged DLL that exports a C type function, or is it a
managed DLL? The ways you would do this are very, very different.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VJ said:
I will have the path of a DLL i.e C:\Test\Test.dll and a Method name in
the DLL say ExecuteMe(string arg1, int arg2). I want to be able to load
the DLL at run-time and execute this method. I also want to be able to
capture the return value of the Method.

Vijay
 
Back
Top