VB to VB.net conversion buffer string problem ?

CdRsKuLL

Active member
Joined
Sep 26, 2006
Messages
40
Programming Experience
Beginner
Hi peeps,

well I've looked and looked + tryed debugging but I'm not getting anywhere fast :-(

I'm trying to import a usb radio driver and I'm 99% there. I can turn it on / off and get / set the freq.. but I'm struggling to get the rds name from it. The VB code for the function is ...

Public Function WVB_GetModuleName() As String

Dim sBuffer As String * 256
Dim iBufferLen As Integer
Dim lRet As Long

If (VB_GetModuleName(sBuffer, iBufferLen)) Then
WVB_GetModuleName = Left(sBuffer, iBufferLen)
End If

So.. its falling over on the As String * 256. Now I've tried afew different things but they are still returning either a string full of blanks or nothing at all.

I've tried Dim sBuffer As String = Space(256) but that just returns a space filled string.

been at it for a few hours now and drawn a blank. When debugging the iBufferLen does come back with different values so that bits working.. just the sBuffer.

Any help would be greatly appreciated.

thanks

Steve
 
Well.. I had problems with importing the DLL which worked fine in VB, so I'm using the below method

Old VB..
Public Declare Function VB_GetRDSText Lib "USBRadio.dll" (ByVal sRDSBuffer As String, ByRef iRDSLenght As Integer) As Boolean

VB.Net 2010
<System.Runtime.InteropServices.DllImport("USBRadio.dll")> _
Private Function VB_GetRDSText(ByVal sRDSBuffer As String, ByRef iRDSLenght As Integer) As Boolean
End Function

The source is available of the DLL but that's getting a little deep for me.. silabsradiodll - This is a windows DLL designed make it possible to use the Silabs Radio in your own projects - Google Project Hosting

The other functions like get / set freq etc all work find and it does return a length of the string, just not populate it.

Many thanks for your help.. just got this last thing to do and the radio parts complete. :)

Steve
 
First up, if that second parameter was type Integer in VB6 then it should be type Short in VB.NET.

As for the first parameter, there's no such thing as a fixed-length String in VB.NET. You might try using type StringBuilder instead of type String. Create a new StringBuilder with a Capacity of 256 and see if that works.
 
Hi, many thanks for the reply.. I've tried to have a go at stringbuilder but I'm stuck on what to send. I've tried append but it just underlines it ...


Public Function WVB_GetRDSPS() As String

'Dim sBuffer As String
Dim sb As New StringBuilder(256)
Dim iBufferLen As Integer

If (VB_GetRDSPS(sb, iBufferLen)) Then <-- this line
WVB_GetRDSPS = Left(sb.ToString, iBufferLen)
Else
WVB_GetRDSPS = ""
End If

End Function

thanks again for your help.

Steve
 
Just thought I would let you know I've got it working.. just incase others follow this is what I've done..

<System.Runtime.InteropServices.DllImport("USBRadio.dll")> _
Function VB_GetRDSPS(<MarshalAs(UnmanagedType.LPArray)> ByVal lpBuffer As Byte(), ByRef s As Int16) As Boolean
End Function

and to call it...

Public Function Radioname() As String

Dim szRetRDS As Byte() = New Byte(7) {}
Dim s As Int16 = 0

If VB_GetRDSPS(szRetRDS, s) Then
If s > 0 Then Radioname = System.Text.Encoding.ASCII.GetString(szRetRDS) Else Radioname = ""
Else
Radioname = ""
End If

End Function


Again, thanks for your help.. much appreciated as it put me on the right track.

Steve
 
Back
Top