[Last Call] Learn how to a build a cloud-first strategyRegister Now


How to make DLL?

Posted on 2011-10-12
Medium Priority
Last Modified: 2012-05-12
How to make DLL and how to use it in applicaiton in Visual studio 2005 with C#?
Question by:heemandalal

Expert Comment

ID: 36956198

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

Expert Comment

ID: 36956232

Expert Comment

ID: 36956847
     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.

LVL 13

Accepted Solution

Naman Goel earned 500 total points
ID: 36957496
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.
LVL 13

Expert Comment

by:Naman Goel
ID: 36957547
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


Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question