Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2005, 10:40 PM
Registered User
 
Join Date: Apr 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to lsxx
Default How to use DLL in C#?

Why does it cannot work?Could you tell me the mistake?
or tell me other methods that can use DLL.
Thanks very much!!!

Codes are below:

1)This is a dll code:

using System;
namespace myClassLib
{
    public class myCL
    {
        public myCL()
        {
        }

        public double Add(double i,double j)
        {
            return(i+j);
        }
    }
}

2)This is my mainframe:

using System;
using myClassLib;

namespace test1
{
        .......

        myCL cl=new myCL();

        [STAThread]
    static void Main()
    {
        Application.Run(new Form1());
    }

    private void btn_equal_Click(object sender,System.EventArgs e)
    {
        double js=3,bjs=2;
        try
        {
        this.label1.Text=cl.Add(js,bjs).ToString();
        }
        catch
        {
        }
    }
}


Candle
 
Old April 30th, 2005, 02:42 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

because when you compile your codes to a DLL file you should add its reference in the destination application(or copy the DLL file to the /Bin directory of the destination app).

_____________
Mehdi.
software student.
 
Old May 1st, 2005, 03:16 AM
Registered User
 
Join Date: Apr 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to lsxx
Default

Thanks,mehdi62b!
I have added the reference in the DLL codes,and the error reads :"cannt find the namespace myClassLib".

Candle
 
Old May 2nd, 2005, 06:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I suppose you are using Visual Studio... You have to add the reference in the Solution Explorer; that is, you have to let the project, which holde the Main method, know which .dll file the namespace myClassLib is in.

Therefore if the two .dll's are in the same solution you have to right-click the References folder in the Solution Explorer and click Add reference. Then select the Projects tab sheet and then select the project which have the .dll file with myClassLib. Finally click OK and then compile.

Hope it helps, Jacob.





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert unmanaged dll to managed dll nitesh kumar Visual C++ 2005 0 August 4th, 2008 04:53 AM
Install problems - VS 6.0 on XP SCRRUN.DLL PDM.DLL jeff4444 Visual C++ 0 December 6th, 2006 08:48 PM
How to convert .NET dll to COM dll used by VB 6.0 gvprashanth .NET Framework 1.x 0 December 4th, 2006 05:05 AM
The database dll crdb_oracle.dll could not be load Yeliz Crystal Reports 0 October 18th, 2006 08:12 AM
DLL & Excel - keep having to reset DLL reference! James Diamond Pro VB 6 2 May 25th, 2004 03:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.