Solved

DLL Classes and running functions

Posted on 2006-11-01
3
213 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
3 Comments
 
LVL 12

Expert Comment

by:guidway
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now