How to make DLL?

Posted on 2011-10-12
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
    LVL 3

    Expert Comment


    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
    LVL 9

    Expert Comment


    Expert Comment

         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

    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
    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now