Results 1 to 8 of 8

Thread: VB to VB.net conversion buffer string problem ?

  1. #1
    CdRsKuLL is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    40
    Reputation
    98

    VB to VB.net conversion buffer string problem ?

    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

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,782
    Reputation
    1620
    What does VB_GetModuleName look like? Is it your own method or someone else's?

  3. #3
    CdRsKuLL is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    40
    Reputation
    98
    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("USBRadi o.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

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,782
    Reputation
    1620
    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.

  5. #5
    CdRsKuLL is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    40
    Reputation
    98
    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

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,782
    Reputation
    1620
    Have you changed your method declaration so that the parameter is type StringBuilder? You can't pass a StringBuilder to a method that expects a String.

  7. #7
    CdRsKuLL is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    40
    Reputation
    98
    hiya, sorry completely lost me now :-(

  8. #8
    CdRsKuLL is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    40
    Reputation
    98
    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("USBRadi o.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

Bookmarks

Posting Permissions

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