Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone.
I have this dll named dllSource.dll, and it contains:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dllSource
{
    public class Operation
    {
        public int Add(int x, int y)
        {
            int z;
            if ((x == 10) && (y == 20))
            {
                z = x + y;
            }
            else
            {
                z = x;
            }
            return z;
        }
    }
}


What I intend to do is to call that dll and pass parameters on it.
I want to pass 5 to x and 10 to y.
How will I so that?
Also, if I want to get the parameter type of the dll, how will I do it?

Thanks
Posted
Updated 21-Mar-13 14:32pm
v2

1 solution

You will need to add your dllSource.dll to the References of your other project.
In the code for that project include a line using dllSource;
Now you can use the class in your dll like any other class or type. E.g.
C#
private void button1_Click(object sender, EventArgs e)
{
    Operation o = new Operation();
    int i = o.Add(5, 10);
    // ... etc
}


To get the parameter type(s) and return type ...

A) Manually - Right-click on the dllSource in the References section of Solution Explorer and select "View in Object Browser"

B) Whilst typing code - using my code above as an example type o. and allow the intellisense to display then hover your mouse over the function you want the information on.

C) Programmatically - Use Reflection - have a look at this article[^]

[Edit] prompted by comment below ... you will need to declare the class and function as public for any of the above to work
 
Share this answer
 
v2
Comments
toATwork 21-Mar-13 9:16am    
Manually won't work. Default visibility of class is internal.
If you have the source of the other dll ensure the class is declared public. Then you can instantiate it from other assemblies.
Member 9886727 21-Mar-13 21:20pm    
Hi Chill60 and toAtwork,

I already updated my class in dll to public.

It seems that I am unable to create an object from it using:

object o = assembly.CreateInstance("Operation");

May I see the sample code on how to do this, please.
Thanks
CHill60 22-Mar-13 5:19am    
Are you saying that you can't add a reference to this dll into your project? Have a look at (a lot) of comments on this link if that is the case http://stackoverflow.com/questions/465488/can-i-load-a-net-assembly-at-runtime-and-instantiate-a-type-knowing-only-the-na

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900