How to create a dll file

12,353

Solution 1

A Class Library is just that, a library of code, you need to create an application that references the library to try it out.
In the same solution, just add a new project as a Winforms Application and then in the winforms application project add a reference to the class library project.

You should then be able to call the methods in the library from the application code.

Solution 2

To create a DLL File, click on New project, then select Class Library.

Enter your code into the class file that was automatically created for you and then click Build Solution from the Debug menu.

Now, look in your directory: ../debug/release/YOURDLL.dll

There it is! :)

P.S. DLL files cannot be run just like normal applciation (exe) files. You'll need to create a separate project (probably a win forms app) and then add your dll file to that project as a "Reference", you can do this by going to the Solution explorer, right clicking your project Name and selecting Add Reference then browsing to whereever you saved your dll file.

Then, to be able to use this dll file, in your projects code, you call the methods inside the dll file. For example:

If, in your DLL file you have a method like this:

public string somerandommethod()
{
   string x = "something";
return x;
}

Then, in your Form1.cs file of your separate project, you would call the code from your dll file like this:

button1_Click(object sender, EventArgs e)
{
    MyDllFile dll = new MyDllFile();
    MessageBox.Show(dll.somerandommethod());
}

I hope this has helped you

Share:
12,353
Gopal
Author by

Gopal

Updated on June 04, 2022

Comments

  • Gopal
    Gopal almost 2 years

    Using Visual Studio 2005

    I have list of class files, when i try to run the class files, it showing error as "a project with output type of class library cannot be started directly"

    How to run the class file? How to create a dll file.

    Am new to visual studio 2005

    Need Help?