How to create a DLL file in Visual Studio
The .dll is a portable executable (PE) file format. It helps us to reuse the same code in many applications simultaneously. Many development tools or IDE (Integrated Development Environment) supports dll creations. This article describes how to create a C# class library, step by step dll creations. Summary of the article:
- What is DLL file?
- Creation of a Class Library
What is DLL file?
A DLL is a library that contains code and data that can be used by more than one program at the same time. For example, the Comdlg32 DLL performs common dialog box related functions, in Windows operating systems. This helps us to reuse same code and efficient memory usage. By creating dll we can modularized a program into separate components.
A DLL is a library that contains code and data that can be used by more than one program at the same time. For example, the Comdlg32 DLL performs common dialog box related functions, in Windows operating systems. This helps us to reuse same code and efficient memory usage. By creating dll we can modularized a program into separate components.
Creation of a Class Library
In Microsoft Visual Studio we can easily create an ASP.NET Class Library Project. The steps that create an ASP.NET Class Library Project are given bellow:
In Microsoft Visual Studio we can easily create an ASP.NET Class Library Project. The steps that create an ASP.NET Class Library Project are given bellow:
Step 1
If you have Microsoft Visual Studio installed, Start it and select New Project from the file menu.
If you have Microsoft Visual Studio installed, Start it and select New Project from the file menu.
- In the New Project dialog box:
- Open the Visual C# templates.
- Select the template Class.
- Set the project name to MyCalculator.
- Set the disk location to something like C:\TestProject.
- Click OK.
Step 2
New project will be created and the Solution Explorer will be like this:
Rename the “Class1.cs” file as “Calculator.cs”. A confirmation message will be displayed. Click Yes.
New project will be created and the Solution Explorer will be like this:
Rename the “Class1.cs” file as “Calculator.cs”. A confirmation message will be displayed. Click Yes.
Step 3
Double click the Calculator.cs file. Create a method named “Sum” that takes two integers value and return the sum. Sample C# code is given bellow:
Double click the Calculator.cs file. Create a method named “Sum” that takes two integers value and return the sum. Sample C# code is given bellow:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyCalculator { public class Calculator { public int Sum(int x, int y) { return x + y; } } }
Step 4
Build the application from the Build menu. DLL is now created and it is located at bin\debug directory of the Application/Project. Its name is “MyCalculator.dll”. Generally the name of a DLL is as like as the Application/Project name. “MyCalculator.dll” is now ready to use. We can use it by creating another Application/Project and calling this DLL.
Build the application from the Build menu. DLL is now created and it is located at bin\debug directory of the Application/Project. Its name is “MyCalculator.dll”. Generally the name of a DLL is as like as the Application/Project name. “MyCalculator.dll” is now ready to use. We can use it by creating another Application/Project and calling this DLL.
In this way we can create a DLL file by using Visual Studio 2010.
The DLL is one of the most innovative creations of Microsoft. It provides numerous facilities. It helps us to protect our codes, reduce code redundancy and memory space.
No comments