CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: C# DLL call

  1. #1
    Join Date
    Feb 2010
    Posts
    8

    C# DLL call

    Question from Newbie:
    I want to create a DLL called AddOne.DLL that has one function in it called "OneMore" that accepts an integer as input and returns the next greatest integer value (ie: if i pass it 212, i want it to return 213). I then want to call this from a windows forms application.

    My question is:
    1) how do i create a function that returns a value.
    2) how do i call this external function from another C# windows forms app.

    This is probably the dumbest question ever posted, but i am an old VB programmer and all this is new to me.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,274

    Re: C# DLL call

    Let's start with the basics. Do you know how to:
    1) create a forms project?
    2) create a class library project?
    3) reference a class library from a project?
    4) create a class?
    5) create a method in a class?

  3. #3
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: C# DLL call

    Good starting point from Arjay. I would add this:

    1. Have you had a look at MSDN?

    2. Have you had a look at MSDN video tutorials?

    3. Have you looked at any books on the C# and Windows development?

    Your question is not dumb but it is not (or at least shouldn't be the norm) in this forum. Generally people ask questions about a specific problem that they are facing (or ask for advice about a specific thing). You are starting from scratch and there is no indication that you have done any research yourself. Hence a you are getting questions before any concrete answers. Not a problem as people here generally like to help no matter how trivial or complex the problem.

  4. #4
    Join Date
    Feb 2010
    Posts
    8

    Re: C# DLL call

    Yes, I created the DLL and have that saved. I have then created a Windows Forms app with just the public void main function. I have put a textbox and button on the form. In the textbox i want to enter the number i want to add one to. I have referenced the DLL from within my forms app.
    I guess i am not clear on creating a class or a method. In VB we called a function anything that returned a value. Do you have the same kind of thing in C#?

  5. #5
    Join Date
    Feb 2010
    Posts
    8

    Re: C# DLL call

    I have done a lot of exploring and have signed up for $1,500 worth of AppDev online training. I cannot really seem to find what i am looking for. The AppDev i know is going to be a several month ordeal to get thru.
    I am hoping if somebody can give me a shove in the right direction i can take it from there.
    If i am posting to the wrong form, could you tell me where i should be posting? I don't want to post to the wrong group.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,274

    Re: C# DLL call

    In C#, there are no functions - functions imply a standalone entity.

    A method is the equivalent of a function, but it's a part of a class. As such there are only methods in C#.

    Declaring a method is simple (inside your dll assembly).

    Code:
     
    public class AddOne
    {
      public int OneMore( int value )
      {
        return value + 1;
      }
    }

  7. #7
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: C# DLL call

    Quote Originally Posted by pmann461 View Post
    1) how do i create a function that returns a value.
    oh man!

    Quote Originally Posted by pmann461 View Post
    This is probably the dumbest question ever posted, ...
    this question is not actually dumb. this is however the wrong place to ask it.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  8. #8
    Join Date
    Feb 2010
    Posts
    8

    Re: C# DLL call

    Great! Got it!
    OK, how do i call this method from the Windows Forms app?

    btw - i cannot understand a single word on the MSDN site. Even when i know the subject, they do nothing but confuse me.

  9. #9
    Join Date
    Feb 2010
    Posts
    8

    Re: C# DLL call

    Quote Originally Posted by memeloo View Post
    oh man!


    this question is not actually dumb. this is however the wrong place to ask it.
    Sorry!
    Can you please tell me where i should be posting?

  10. #10
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: C# DLL call

    Quote Originally Posted by pmann461 View Post
    Sorry!
    Can you please tell me where i should be posting?
    nowhere, you should read some book first.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,274

    Re: C# DLL call

    Btw, in C# dlls are usually referred to as assemblies. Dlls kind of refer to the Windows binary types (vs. an exe).

    In .Net, there are multiple types of assemblies but they all end up on the file system as an exe or a dll.

    While a dll is a dll, it may not be a .net assembly (if the dll doesn't contain managed code).

    Similarly an exe is an exe, but it may not be a .net assembly (if the exe doesn't contain managed code).

    I mention all this because usually in .net land when you refer to a DLL, it usually implies a native Win32 dll - usually in the context of pinvoking to the dll. Btw, PInvoking allows a .net assembly to interact with a non-managed Win32 dll.

  12. #12
    Join Date
    Feb 2010
    Posts
    8

    Re: C# DLL call

    Quote Originally Posted by memeloo View Post
    nowhere, you should read some book first.
    Thanks. I am stumbling thru the Head First C# book. Can you recommeed a better one for beginners?

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,274

    Re: C# DLL call

    Quote Originally Posted by pmann461 View Post
    Great! Got it!
    OK, how do i call this method from the Windows Forms app?

    btw - i cannot understand a single word on the MSDN site. Even when i know the subject, they do nothing but confuse me.
    Msdn can be a bit confusing at first - especially if you are used to another style of documentation, but let me tell you - MSDN is a fantastic source of information although it does take a bit to get used to. I highly recommend that you visit MSDN often to look at different class, methods and so on in the .net library.

    At first it's a bit tough because you won't know what to search for, but you should always give it a try first before posting to a forum such as this. Sometimes, we'll answer questions with "search google for 'x y z'" giving you the search terms. Part of having experience is to know what to search MSDN and google for.

    If you force yourself to find things in MSDN and google (before posting), you'll get up to speed quicker and won't have to wait for a response on a forum.

    For example, I have over 6K posts on this forum and probably only have asked about 20 questions. I'm not particularly smart, but I have a black belt in google. I don't know the answer to every question I answer either - often times I look it up in msdn or google before posting the reply. I can't stress the importance of being able to find information on your own through MSDN or google.

  14. #14
    Join Date
    Feb 2010
    Posts
    8

    Re: C# DLL call

    Ok, thank you for your time. I will continue to search and read. I will be back to this form when i am more 'up to speed'. Thanks again for your time and kind replies.

  15. #15
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: C# DLL call

    Quote Originally Posted by pmann461 View Post
    Thanks. I am stumbling thru the Head First C# book. Can you recommeed a better one for beginners?
    For what you need to learn at moment I don't think you'll find a better book. MSDN is a fantastic resource. In order for it to be used effectively you need to have had some experience with the style of documentation and general programming experience with strongly typed languages like C++, Java and of course C#. The examples are small, to the point without a lot of explanations (in other words ideal for the person who knows exactly what he is looking for and can fill in the blanks). I wish you all the best in your learning.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)