Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. VB.net dll use with C# windows form

VB.net dll use with C# windows form

Scheduled Pinned Locked Moved C#
csharpcomhelpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BobbyStrain
    wrote on last edited by
    #1

    I have a VB.NET class library with a single public function with a single parameter that calls a method to produce the string return value. I referenced it in the C# project, and added a using statement for the namespace. However, I have no success in even coding to use the function from the dll. Can someone point me in the right direction? There are lots of answers to the problem on the web, but none work for me. Here is a portion of the VB dll code. GetSeparators() prepares and returns the string. I am developing the library to get information from a COM library. I have not found a convenient code for C# to use the COM library. The VB dll is NET 3.5 and the C# app is NET 4.6.1.

    Public Class HYSYSFetch

    Private \_filename As String
    Private \_sepstring As String = ""
    
    Public Function FetchSeparators(filename As String) As String
        \_filename = filename
        GetSeparators()
        Return \_sepstring
    End Function
    
    OriginalGriffO 1 Reply Last reply
    0
    • B BobbyStrain

      I have a VB.NET class library with a single public function with a single parameter that calls a method to produce the string return value. I referenced it in the C# project, and added a using statement for the namespace. However, I have no success in even coding to use the function from the dll. Can someone point me in the right direction? There are lots of answers to the problem on the web, but none work for me. Here is a portion of the VB dll code. GetSeparators() prepares and returns the string. I am developing the library to get information from a COM library. I have not found a convenient code for C# to use the COM library. The VB dll is NET 3.5 and the C# app is NET 4.6.1.

      Public Class HYSYSFetch

      Private \_filename As String
      Private \_sepstring As String = ""
      
      Public Function FetchSeparators(filename As String) As String
          \_filename = filename
          GetSeparators()
          Return \_sepstring
      End Function
      
      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      All you have to do is create an instance of the containing class, and call the function on that

      private void MyFunction()
      {
      HYSYSFetch hsf = new HYSYSFetch(...); // Fill in the details from your constructor
      string result = hsf.FetchSeparators(strPathToFile);
      }

      If that doesn't work, you need to tell us exactly what you get as an error message, and show us the exact code you tried.

      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      B 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        All you have to do is create an instance of the containing class, and call the function on that

        private void MyFunction()
        {
        HYSYSFetch hsf = new HYSYSFetch(...); // Fill in the details from your constructor
        string result = hsf.FetchSeparators(strPathToFile);
        }

        If that doesn't work, you need to tell us exactly what you get as an error message, and show us the exact code you tried.

        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        B Offline
        B Offline
        BobbyStrain
        wrote on last edited by
        #3

        Thank you. This is something I have done a hundred times with projects. But I never used a VB dll with a C# project. I shall remember that the right solution is the simple one.

        OriginalGriffO 1 Reply Last reply
        0
        • B BobbyStrain

          Thank you. This is something I have done a hundred times with projects. But I never used a VB dll with a C# project. I shall remember that the right solution is the simple one.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Once they are compiled, VB and C# DLLs are the same thing - you can treat them as if they were written in any language. (The same applies to any language which compiles to IL, so F#, Cobol, C++ - all "look the same" once compiled.)

          Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          B 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Once they are compiled, VB and C# DLLs are the same thing - you can treat them as if they were written in any language. (The same applies to any language which compiles to IL, so F#, Cobol, C++ - all "look the same" once compiled.)

            Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

            B Offline
            B Offline
            BobbyStrain
            wrote on last edited by
            #5

            Griff, Once you cleared the fog and got me started, the rest was easy. Everything works smoothly when the C# application calls the VB.NET library functions. Thanks again. I needed the VB library because C# doesn't easily communicate with a COM object. And I already had the VB code in a VB application. I develop most of my class libraries with C#, just to keep in practice. My VB application that uses Selenium Basic (Selenium wrapper for VB & VBA) doesn't play with Firefox latest editions. So my need to use C# to make use of Selenium which doesn't work with VB. My main use is to get information from a process simulator and transfer it to a web page, thus eliminating transcribing errors. This takes several technologies to get it to work.

            OriginalGriffO 1 Reply Last reply
            0
            • B BobbyStrain

              Griff, Once you cleared the fog and got me started, the rest was easy. Everything works smoothly when the C# application calls the VB.NET library functions. Thanks again. I needed the VB library because C# doesn't easily communicate with a COM object. And I already had the VB code in a VB application. I develop most of my class libraries with C#, just to keep in practice. My VB application that uses Selenium Basic (Selenium wrapper for VB & VBA) doesn't play with Firefox latest editions. So my need to use C# to make use of Selenium which doesn't work with VB. My main use is to get information from a process simulator and transfer it to a web page, thus eliminating transcribing errors. This takes several technologies to get it to work.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              You're welcome!

              Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              B 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                You're welcome!

                Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                B Offline
                B Offline
                BobbyStrain
                wrote on last edited by
                #7

                Well, I spoke too soon. The VB dll is not playing well with the C# app. The C# app doesn't recognize a particular method in the dll. Call to a different method works OK. Throws an error, something about Reflection and the wrong number of arguments. But the number of arguments is correct; there is only one. I had an earlier version working, but the C# app was not getting the proper data from the dll which fetches data from a COM app. I'll have to go back to an earlier version and trace the problem.

                M 1 Reply Last reply
                0
                • B BobbyStrain

                  Well, I spoke too soon. The VB dll is not playing well with the C# app. The C# app doesn't recognize a particular method in the dll. Call to a different method works OK. Throws an error, something about Reflection and the wrong number of arguments. But the number of arguments is correct; there is only one. I had an earlier version working, but the C# app was not getting the proper data from the dll which fetches data from a COM app. I'll have to go back to an earlier version and trace the problem.

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  Don't forget the error may have "bubbled up" from a method below the one you are calling.

                  Never underestimate the power of human stupidity RAH

                  B 1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    Don't forget the error may have "bubbled up" from a method below the one you are calling.

                    Never underestimate the power of human stupidity RAH

                    B Offline
                    B Offline
                    BobbyStrain
                    wrote on last edited by
                    #9

                    Turns out I had a few minor errors in the VB code. I found all of them, and cleaned up the code while I was finding them. It all works as it should. I learned a lot with this little project. It was a cascade with a C# app calling a VB.NET dll which in turn called a licensed COM library. So there was lots of opportunity to get the code wrong. Thanks for the help.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups