• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

How to make DLL?

How to make DLL and how to use it in applicaiton in Visual studio 2005 with C#?
1 Solution

It's quite easy. Create a class library project and write a simple class containing only
a function. you should make sure that you have added access control on
the function with PUBLIC. Then, create a new console application and
add project reference from class library project.
You can invoke the function here after initializing a new instance of
the class.

Post a comment if you need code examples!

Hope it helps
     Once you open you Project , right Click on you project --> Click on Application Tab -->  Change the Output type to  CLASS LIBRARY --> Build you application.  Once you build your application ,the project will create a dll in the bin folder and you can use all the function  and classes based on access control of the function in other projects by referencing the dll. Let me know if you have any questions.

Naman GoelSoftware engineer 1Commented:
Follow these steps to build a .NET DLL component from the code you used in the previous class module example:

 1.   Start Visual Studio .NET and open a new Class Library project. In the New Project dialog box, name the project ServerTime.

2. Change the name of the class from Class1 to ServerTime.
3. Either copy the code out of the ServerTime class module you created in the previous example into the new ServerTime class module, or enter the following code into the new ServerTime class module:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class ServerTime

	private DateTime mdtTime;
	public string TimeStamp {
		get {
			mdtTime = DateAndTime.Now();

			return Convert.ToString(mdtTime);

Open in new window

You will now compile this ServerTimer class as a DLL by clicking Build on the Debug menu or by using the Ctrl+Shift+B keystroke combination.

The DLL that results from the build command is placed into the \bin directory immediately below your .NET project directory. By default, the DLL has the same name as your component project. For instance, if you named the project TimeStamp in the New Project dialog, the DLL produced by your project will be named TimeStamp.DLL. This name is also the default Namespace name for the classes contained within the project.

If you followed the steps in this document, your project is named ServerTime. You also named the only class within the project ServerTime. Therefore, your DLL name will be ServerTime.DLL and consumer applications of this DLL will reference ServerTime.ServerTime to create an object of this class.
Naman GoelSoftware engineer 1Commented:
Create a DLL Consumer Application

Once the DLL project has been compiled, its services are available to any Windows Form or WebForm .NET application. In this section, you will build a simple Windows Form consumer application that uses the ServerTime class to retrieve the computer's date and time.

Follow these steps to create the consumer application:

    Start Visual Studio .NET, select Windows Application as the new project type, and name the project DLLConsumer1.
    Set the Name property of the default Windows Form to frmConsumer.
    Add a button control to the default Windows Form and name it btnGetServerTime.
    Add a TextBox to the form and name it txtServerTime.

You need to set a reference to the ServerTime DLL so that this form will be able to consume the components services. Do this by following the steps below.

1.    To open the Add Reference dialog box, on the Project menu, click Add Reference.
2.    Click the Projects tab and then click Browse to locate the component DLL built in the preceding section
3.       Select the ServerTime.DLL file, click Open, and then click OK.

The Solution Explorer,  now shows the ServerTime component added as a reference in your application. What this means is that all of the classes, along with their properties, methods, and events, are now available to your consumer application.
Add a Windows Form and add a button to it rename the button to btnGetServerTime
Add click event to btnGetServerTime
add following code to click event:

private void btnGetServerTime_Click(System.Object sender, System.EventArgs e)
	ServerTime st = new ServerTime();

	txtServerTime.Text = st.TimeStamp;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now