Using DLL files in Visual Studio 2005 using C#
This article explains the procedure of creating DLL files using visual studio 2005. It is very quick and easy to learn.
Part 1: Creating a Class Library (DLL)
In this section, we will learn how to create a simple DLL file
1. Open a New Project as shows below and Select Class Library from the templates.
Select the File Name and the Location where you want to save this file.
2. This is what you will see on the main window.
Now create a simple function in the class Class1.
In this case I have created the highlighted function to add two numbers.
3. Now, select Build Solution from the Build Menu in the Menu Bar.
4. Here is the DLL file created in the Debug folder.
Now this DLL file can be copied and pasted anywhere and can be used by any number of programs at a given point of time.
Part 2: Using a Class Library (DLL)
In this section, we will learn how to use the DLL file that we have created.
Namespace we used : MyDLL
Class : Class1
Function : addnumbers(int a. int b)
1. Create a new Windows Application.
2. Build a Simple Windows Form as Shown Below.
3. Now, we need to add the Reference of the DLL file that we had created earlier.
4. Select the DLL file from the browse tab.
5. Now, we will use the class and the namespace of the DLL file.
Click on the button to generate an EventHandler
Make a Note of the namespace that has been added to the coding.
6. Create a new object of the class. Now add the member function of the class with the help of the Object c.
7. This is how the event handler will look like.
8. Now, run the program.And, here is the output.
This is just a simple dll file created. We can create DLL file for any method and use it anywhere we like.