Solved

DLL Classes and running functions

Posted on 2006-11-01
3
216 Views
Last Modified: 2010-04-16
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
Comment
Question by:cossy74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:guidway
ID: 17855253
see:
http://my.execpc.com/~gopalan/dotnet/reflection.html 

under the section
"Obtaining Member Information from a Class"
0
 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 17856198
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
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 17857001
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question