Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: C# dll

  1. #1
    New Coder complete's Avatar
    Join Date
    Jul 2005
    Location
    USA
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    C# dll

    After someone creates a DLL in C# using the Microsoft Visual development environment, how would another programmer take that code, make a new project that includes the DLL's source and make a GUI that uses the DLL'S API?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You need to take the physical dll and add it under you're resources (so make sure you have a local copy).

    I no longer have visual studio, but I recall there is an actual folder in you're navigation pane. Simply right click that or you're project and select to add a resource. If its not there, you can get to it under you're project properties as well, or under tools. There are a few places you can get to you're resources.

    Testing is always a pain though, make sure you compile and run on local disks only or you may have problems with running it via networked drives (permission problems, it will deny you network access). This goes for any dll you resource into you're c# project.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    If you want to add it to a C# application, you just add the DLL as a reference under the project. In the solution explorer window it lets you do that. If you want to use that C# DLL in say a C++ program, it becomes more complicated because the C# DLL has to be compiled with COM support.
    OracleGuy

  • #4
    New Coder complete's Avatar
    Join Date
    Jul 2005
    Location
    USA
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have done a few things. I have created a console app to use as the front-end to the project. Then I have added the DLL as a reference like this:

    1) In the Solution Explorer right-click "References" and select "Add Reference ...".

    2) Select the "Browse" tab.

    3) Navigate to the DLL and select it.

    4) Add the appropriate using directive to the code file(s) where you want to use the DLL.


    I have also found that I can add the Project that the DLL was made in into my new Solution file.

    I have included the namespace of the DLL in the "using" section of my code.

    And the intelligent type I am using recognizes this class when I declare it in my code.

    But it does not seem to recognize all the methods (api's) of the class.

    What am I doing wrong?



    Strangely, "Equals", "GetHashCode", "GetType" and "ToString" are not seen in the DLL's source code for available methods for this class.

    Also, I know that if you double click on the added reference, an Object Explorer should come up showing the available methods. This is not what happens:



    So now to look closer at the DLL source code.Could there be a problem in the fact that the constructor ( private NookieBookieDoopieDoo() ) is
    defined as a privvate? Could there be a problem that the methods are static?

    It looks something like this:

    Code:
    namespace BladaFlabaDab
    {
    
        public class NookieBookieDoopieDoo
        {
    
            private static readonly string SomethingYouDoNotNeedToKnow = @"SLAMADAMNADDORK";
    
            private NookieBookieDoopieDoo()
            {
            }
    
    
    
            public static void Send(string to, string subject, string body)
            {
                .
                .
                .
            }
    
            public static void Send(string to, string replyTo, string subject, string body)
            {
                .
                .
                .
            }
    
            private static void InitializeClient()
            {
                .
                .
                .
            }
        }
    }
    Could there be a problem in the fact that the constructor ( private NookieBookieDoopieDoo() ) is
    defined as a privvate? Could there be a problem that the methods are static?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Private constructors are fine, and as long as you're static methods are public they are also fine. I see you're class is also public, which is good (I'm thinking that I recall visual studio having a problem with defining internal instead of public when it thinks it can get away with it).

    Anyway, its you're usage thats wrong.
    Code:
    MyClass thing;
    thing.*;
    thing hasn't been assigned a value, and it cannot be constructed as a new type of MyClass. Insead, you want to use MyClass.* for you're methods.

    Thing has those methods showing up since they are a part of object (equals, gettype, gethashcode and tostring). Thing doesn't exist as an actual object by this point, but it does exist as a MyClass in memory (which is why the auto complete provides you with values).

    Edit:
    Any reason as well why you would remove the text from you're classes? All that important information is listed there.
    Oh, and don't forget the top tabs as well :P
    Last edited by Fou-Lu; 12-02-2008 at 01:15 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by Fou-Lu View Post
    Anyway, its you're usage thats wrong.
    Code:
    MyClass thing;
    thing.*;
    thing hasn't been assigned a value, and it cannot be constructed as a new type of MyClass. Insead, you want to use MyClass.* for you're methods.

    Thing has those methods showing up since they are a part of object (equals, gettype, gethashcode and tostring). Thing doesn't exist as an actual object by this point, but it does exist as a MyClass in memory (which is why the auto complete provides you with values).
    That is the exact source of the problem. When you instantiate the class like you are doing, it doesn't show the static methods. Do what Fou-Lu laid out and it will work.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •