Create DLL Using Visual Basic.Net

A DLL (Dynamic Link Library) is a file that can be loaded and executed by programs dynamically. The main advanatage in using DLL is several can use the same DLL during their execution.

Use of DLL (Dynamic Link Library)

Here are the key points that will guide you in understanding DLL.

  • When we want to hide our code from the user then we make DLL (Dynamic Link Library) and add these in other application now no body can open this.
  • When we want to use same code in different applications (REUSABILITY) then we make DLL of that code and add that code in other applications.
  • When you want to use Functions of C# in Vb.net then you will make DLL of C# and add this library in VB.net and can easily use its functions.

Examples:

There are many Examples of DLLs in .net. You are familiar with different DLLs like

—————————————————————-

System.Data

System.Drawing

System.Globalization

—————————————————————-

Now here System is a DLL and further are its classes. We can make classes in a class and make functions in class like

—————————————————————-

System.Data.SqlClient

SqlClient is a class in Data Class.

System.Data.SqlClient.SqlConnection

—————————————————————-

Now in this sqlconnection is a function of class sqlclient. We all know that we can just use these functions but can’t see there code. So this is a very useful concept.

This is a Advance topic but if beginner study this they can do this easily. In this simple article you will learn to make DLL (Dynamic Link Library) in VB.Net application.

Follow these steps to  make new DLL

—————————————————————

File New Project

Now open a new window with title New Project. Now select Class library from this and write its name MyDLL and Press OK.

Now there is no form in this project there it shows Class1.vb file. Now you can write code of your specified function which you want in your DLL.

—————————————————————-

Public Class Class1

End Class

—————————————————————-

Initially here is this code only for class. Now you can create your own function in this class. We will write functions for addition of two number, subtraction of two numbers, multiplication of two numbers, division of two numbers.

—————————————————————-

Public Class Class1

Public Function ADD(ByVal first As Integer, ByVal sec As Integer)

Dim abc As Integer

abc = first + sec

Return abc

End Function

 

Public Function Subtraction(ByVal first As Integer, ByVal sec As Integer)

Dim abc As Integer

abc = first – sec

Return abc

End Function

 

Public Function Multiplication(ByVal first As Integer, ByVal sec As Integer)

Dim abc As Integer

abc = first * sec

Return abc

End Function

 

Public Function Division(ByVal first As Integer, ByVal sec As Integer)

Dim abc As Integer

abc = first / sec

Return abc

End Function

End Class

—————————————————————-

Now This is the code and your own DLL is ready for attach with some other application.

This is a Advance topic but if beginner study this they can do this easily. In this simple article you will learn to use DLL (Dynamic Link Library) using VB.Net.

Follow these steps to  ADD new DLL

First create a new project and now

Select DLL file and place it in the project folder which you make before.

Project Add References

Now there opens a window it has three tabs select third tab named projects. Now browse DLL file MyDLL which you place before and press OK. Your DLL is added in references of project. Now you can use it easily.

Now drag two numeric up down, four buttons and a textbox on the form1.

—————————————————————-

Numeric Up Down 1 having name txt1.

Numeric Up Down  2 having name txt2.

Textbox 1 with name txtresult

—————————————————————-

Now write code on form1 load event

—————————————————————-

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

_HandlesMyBase.Load

TXT1.Value = 5

TXT2.Value = 10

TXTRESULT.Text = 0

End Sub

—————————————————————-

Now write code against buttons

—————————————————————-

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

_HandlesButton1.Click

Dim a As New MyDLL.Class1

TXTRESULT.Text = a.ADD(TXT1.Text, TXT2.Text)

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

_HandlesButton2.Click

Dim a As New MyDLL.Class1

TXTRESULT.Text = a.Subtraction(TXT1.Text, TXT2.Text)

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

_HandlesButton4.Click

Dim a As New MyDLL.Class1

TXTRESULT.Text = a.Multiplication(TXT1.Text, TXT2.Text)

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

_HandlesButton3.Click

Dim a As New MyDLL.Class1

TXTRESULT.Text = a.Division(TXT1.Text, TXT2.Text)

End Sub

—————————————————————-

Now you can make this form using your DLL and nobody can see its code.

Advertisements

About alamzyah
Name : Alamsyah Nick Name : Alamzyah Place of Birth : Jakarta, 04 June 1983 sex : Male Religion : Moslem Region : Jakarta, Indonesia Specialist : IT, Computer mail : alamzyah@gmail.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: