Connecting Tech Pros Worldwide Help | Site Map

Get String From DLL Visual Studio 2008

Member
 
Join Date: Dec 2007
Posts: 121
#1: Aug 16 '09
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...
Expand|Select|Wrap|Line Numbers
  1. Public Class Class1
  2.     Public Sub RegCheck()
  3.         Dim readValue As String
  4.          readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\MySoft", "SomeKey", Nothing)
  5.     End Sub
  6.  
  7. End Class
I can call RegCheck() but i cannot get readValue


Expand|Select|Wrap|Line Numbers
  1. Imports Trial
  2.         Dim ck As New Trial.Class1
  3.         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's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#2: Aug 16 '09

re: Get String From DLL Visual Studio 2008


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.
Member
 
Join Date: Dec 2007
Posts: 121
#3: Aug 17 '09

re: Get String From DLL Visual Studio 2008


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.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#4: Aug 17 '09

re: Get String From DLL Visual Studio 2008


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.

Expand|Select|Wrap|Line Numbers
  1. string Example(string TestMe)
  2. {
  3.    return TestMe + ". That's what I mean.";
  4. }
  5.  
Another way to get a return is using the out keyword.
MSDN for the out keyword.
Member
 
Join Date: Dec 2007
Posts: 121
#5: Aug 17 '09

re: Get String From DLL Visual Studio 2008


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...
Quote:
Public Function ReturnString()
Dim MyString As String
MyString = "Yep it Worked!"
Return MyString
End Function
This is how i Called it...

Quote:
Imports MyDLL.Class1

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

P.S Thanks tlhintoq
Member
 
Join Date: Dec 2007
Posts: 121
#6: Aug 17 '09

re: Get String From DLL Visual Studio 2008


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.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#7: Aug 17 '09

re: Get String From DLL Visual Studio 2008


Quote:
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.

Quote:
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#.
Reply

Tags
dll, string, vb.net