Monday 26 October 2015

How to make dll files using visual studio ?

Making DLL files

Using visual studio

Step 1

Take a class library project from visual studio.

Step 2

Open the class1 file, which is created by default or add any other as per the choice and requirement.

Step 3

write down the logic part which is need to be used in the related project.

Step 4

Build your project, check the bin > debug folder, you must have got a dll file with the project name.
Example : example.dll

Step 5

Open the project where the dll is needed

Step 6 

Add reference to the dll file by browsing where it was stored.

Step 7

Now add the dll file name with "using" directive.

Step8

Make the object of the class in the dll , which is required at this point.

Step 9

Now use the dll file, as normal class file in your project by sending and receiving arguments as per the project.


Code Example


Class Libray Project file named dllExample


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dllExample
{
    public class Class1
    {
        public int sum(int a, int b)
        {
            return a + b;
        }
        public int multiply(int a, int b)
        {
            return a * b;
        }
        public int subtract(int a, int b)
        {
            return a - b;
        }
    }
}

Project file where dll is used after providing reference

Here, on GUI we have made two TextBox with id txtNo1 and txtNo2, a button and a lblResult to show the output.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using dllExample;
namespace usingDll
{
    public partial class calc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Class1 calculate = new Class1();
            int result = calculate.sum(int.Parse(txtNo1.Text),int.Parse(txtNo2.Text));
            lblResult.Text = result.ToString();
        }
        protected void btnSubt_Click(object sender, EventArgs e)
        {
            Class1 calculate = new Class1();
           int result = calculate.subtract(int.Parse(txtNo1.Text), int.Parse(txtNo2.Text));
           lblResult.Text = result.ToString();
        }
        protected void btnMult_Click(object sender, EventArgs e)
        {
            Class1 calculate = new Class1();
         int result = calculate.multiply(int.Parse(txtNo1.Text), int.Parse(txtNo2.Text));
         lblResult.Text = result.ToString();
        }
    }
}


No comments:

Post a Comment