Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DLL VisualStudio2010
Hi everyone.
I have this dll named dllSource.dll, and it contains:
 
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 21-Mar-13 2:02am
Edited 21-Mar-13 15:32pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
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
  Permalink  
v2
Comments
toATwork at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 4 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100