Get String From DLL Visual Studio 2008

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    Get String From DLL Visual Studio 2008

    Hi Experts,
    i have created a DLL in Visual Studio 2008 Express and i have made reference to it, But i cannot get the value of string readValue.

    This is my DLL...
    Code:
    Public Class Class1
        Public Sub RegCheck()
            Dim readValue As String
             readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\MySoft", "SomeKey", Nothing)
        End Sub
    
    End Class
    I can call RegCheck() but i cannot get readValue


    Code:
    Imports Trial
            Dim ck As New Trial.Class1
            ck.RegCheck()
    Is there something i need to declare ?

    If anyone can enlighten me on how to get this value i would be extremely
    greatfull as i have searched for days.


    Thankyou,
    Gobble.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I can point out this much...
    In the sub in your DLL... Where do you return anything?
    You declare a variable "readValue" .
    You set it equal to the registry key.
    Then... ? Nothing. It is never returned out sent out
    I am probably wrong, but I think you have to create a method that has an 'out' parameter to send the value back.

    Comment

    • gobblegob
      New Member
      • Dec 2007
      • 133

      #3
      Thanks for the reply, So your saying i need to somehow return the value?
      Any idea how to do this?? because i can not find any information about this.
      This is the first time i have worked with creating a DLL.

      Gobble.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I have never built a DLL either. I'm just applying the same logic that a method must return a value in order for the calling function to get something out of it.

        Code:
        string Example(string TestMe)
        {
           return TestMe + ". That's what I mean.";
        }
        Another way to get a return is using the out keyword.
        MSDN for the out keyword.

        Comment

        • gobblegob
          New Member
          • Dec 2007
          • 133

          #5
          Wicked mate i got it working. In the DLL it cant be a "Sub" it has to be a "Function". This is the Code if anyone else is looking how to do it..

          This is in the DLL...
          Public Function ReturnString()
          Dim MyString As String
          MyString = "Yep it Worked!"
          Return MyString
          End Function
          This is how i Called it...

          Imports MyDLL.Class1

          Dim GetMyString As New MyDLL.Class1
          TextBox1.Text = GetMyString.Ret urnString 'ReturnString is the Function
          Sharing is Caring
          Gobble.

          P.S Thanks tlhintoq

          Comment

          • gobblegob
            New Member
            • Dec 2007
            • 133

            #6
            Now i have to try and pass a string to the DLL any idea's?
            Somehow i have to make a function that waits for a string because
            I have no idea how to create a string without having a value in the DLL.
            Any Idea's ?

            why is it so hard to find any info about vb.net and simple DLL handling?
            Gobble.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              Somehow i have to make a function that waits [...]
              Huh? What do you mean "waits"? Why would it be waiting? It doesn't run until you call it. So you pass the string as a parameter when you call it.

              why is it so hard to find any info about vb.net and simple DLL handling?
              have you tried the book store in the programming section? Don't look just at the VB section. Look at the .NET books. since it is the same whether you are looking at VB or C#.

              Comment

              Working...