• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

DLL Classes and running functions

Hi ,

Currently is use the Assembly.LoadFile function to load the DLL. This works :)
Then i use the SampleAssembly.GetTypes in a foreach loop to find the class i want. This works :)

Then i use the following to load the class:
    object oClass = Activator.CreateInstance(oClassType);

My question is, Without knowing the class structure of the DLL Class, how can i call a function inside that class?

0
cossy74
Asked:
cossy74
1 Solution
 
guidwayCommented:
see:
http://my.execpc.com/~gopalan/dotnet/reflection.html 

under the section
"Obtaining Member Information from a Class"
0
 
Mihai StancescuSoftware Engineer Commented:
If its a COM dll and you know its class reference you can call for example:

[DllImport("GDI32.DLL", EntryPoint = "CreateRectRgn")]
        private static extern int CreateRectRgn(int x1, int y1, int x2, int y2);

If its a .Net assembly just put in your using clause the name of the namespace registered in the assembly.

Regards,
Mishu
0
 
existenz2Commented:
You can do that this way:

Type type = typeof(<Object>);
object oClass = Activator.CreateInstance(type);
                  
object[] arguments = new object[0];
object retVal = type.InvokeMember("<Method>",BindingFlags.Default | BindingFlags.InvokeMethod,null,oClass,arguments);


Replace <Object> and <Method> with the correct values.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now