Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> C# >> HOW TO CREATE DLL AND USING THEM IN C#
HOW TO CREATE DLL AND USING THEM IN C#
HOW TO CREATE DLL AND USING THEM IN C#


by Amit Singh on 9/15/2010 12:00:00 AM

Views: 25673       Comments: 4

HOW TO CREATE DLL AND USING THEM IN C#

We have to create DLL with the help of Class Library, and call in a program, here are the steps to create and how it works with the help of an example.

1st Step->open windows application we have to choose Class Library option on the right hand side under the template option and name them Createdll.

CREATE DLL

 

After doing this we have to write a piece of code in .cs file, for the application like Add, subtracts and multiplies. Don’t forget to include the namespace as we have mentioned as namespace CreateDll.  And create a class name as math, under that class you can place a piece of code for Function Add, similarly for Subtract and multiply, as shown below.

 

 

namespace Createdll

{

    public class maths

    {

     //using add function and taking two parameters a and b.

 

        public static long add(long a, long b     

       {

            return (a + b);//return sum of a and b.

        }

 

        public static long sub(long a, long b)

        {

            return (a - b);//return minus of a and b.

        }

        public static long mul(long a, long b)

        {

            return (a * b);//return multiply of a and b.

        }

    }

}

 

 

Next important part is how to build and add references  to the dll.For Building an DLL Just Press F5 or we can click on the file option under that we will find debug option once we click it will be build automatically.

Under the Solution explorer on the right hand side of the corner we can easily see an option like reference as shown below:

 

 

Adding reference of dll created

 

 

Once you click on option then u will get a box like Add References  under that you have to click Browse you need to ADD ur application where ur application Create DLL is placed then click bin then ur name of The application like as shown with the help of arrow.

Adding reference of dll created

After adding reference to createDll library, you can see it as an available namespace as shown below in the screenshot

Reference of DLL added

Next important part is we have to call that CREATE DLL in our application, for that we have to open new windows project  and create a form like that as shown as below .

using created dll

As soon as we have created the Form like above next we have to write a piece of code under the Add, subtract, multiply and clear button.

Don’t forget to place a name space CreateDll same as the DLL which we want to access here with the help of DLL, as follows.

 using Createdll;

place a piece of code under the various button click

namespace irfandll

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

        }

 

        private void btnAdd_Click(object sender, EventArgs e)

        {

            try

            {

                long a, b;

//assigning values of text boxes in variable a and b respectively.

                a = long.Parse(txtInput1.Text);

                b = long.Parse(txtInput2.Text);

//using add method of maths class I had created in class library (Createdll)

                txtInput3.Text = maths.add(a, b).ToString();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

 

        private void btnSubtract_Click(object sender, EventArgs e)

        {

            long a, b;

//assigning values of text boxes in variable a and b respectively.

 

            a = long.Parse(txtInput1.Text);

            b = long.Parse(txtInput2.Text);

//using add method of maths class I had created in class library (Createdll)

 

            txtInput3.Text = maths.sub(a, b).ToString();

 

        }

 

 

 

        private void btnClear_Click(object sender, EventArgs e)

        {

            txtInput1.Text = "";

            txtInput2.Text = "";

            txtInput3.Text = "";

        }

        private void btnMultiply_Click(object sender, EventArgs e)

        {

            long a, b;

//assigning values of text boxes in variable a and b respectively.

 

            a = long.Parse(txtInput1.Text);

            b = long.Parse(txtInput2.Text);

//using add method of maths class I had created in class library (Createdll)

 

            txtInput3.Text = maths.mul(a, b).ToString();

        }

    }

}

 

 

After this process we have to build our application with the help of F5.we will see the output like as shown below

In these of the text field we need to check by putting various no in the text box and one by one we have to check the entire button as Add, Subtract, Multiply, and Clear button.

The desired output will be like that as shown below in the screen shot.

Report Abuse Form
Reason:    
 


DLL
by John Smith 3/25/2011 4:37:49 AM
Good Article Amit.
Report Abuse

Nice Article
by aken H 10/20/2011 7:09:50 PM

hi Amit Singh,

   this a nice article,if can you About dll files in the main purpose or role is what.

thanks!

Report Abuse

Question
by kat harris 5/30/2012 1:57:09 PM
This article was helpful but, not exactly what I was looking for. 
I'm defining a complicated parser and want to save it as a dll in VS 2010 C# how do I do that?

Report Abuse

HOW TO CREATE DLL AND USING THEM IN C#
by Haider M Rizvi 5/31/2012 2:55:30 AM

Hi kat harris,

Can you elaborate your problem.

Thanks.

Report Abuse
Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Amit SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 6067
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2014MindStick. All Rights Reserved.