Partial data result when using Xojo cString for Declare Function (dll).

Hello!

I have this code in VB6 which reads data from card reader.

VB 6.0 Code (sample given and working)
Private Declare Function ReadCARD Lib “Cardlib.dll” (ByVal iShow, ByVal lpDemographic As String, ByVal lpPhoto As String) As Integer

Private Sub btnReadCardWithPhoto_Click()
Dim Demographic As String * 5000
Dim photo As String * 4000
Dim iRet As Integer
iRet = ReadMyKAD(1, 0, Demographic, photo)

If iRet = 0 Then
    'MsgBox "Success"
    MsgBox Demographic
    Dim szFileName As String
    szFileName = App.Path & "\\Data\\photo.jpg"
    Kill (szFileName)
    Open szFileName For Binary Access Write As #2
    Put #2, , photo
    Close #2
    If Dir(szFileName) <> "" Then
        m_Picture.Picture = LoadPicture(szFileName) 'to show photo
    Else
        m_Picture.Picture = LoadPicture("") 'to show photo
    End If
End If

End Sub

Xojo Code
Declare Function ReadCARD Lib “Cardlib.dll” ( iShow As Integer, iPort As Integer, lpDemographic As cstring , lpPhoto As cstring) As Integer

Dim iRet As Integer
dim f as folderitem

Dim Demographic As cString
Dim photo As cstring '(if using As string here the result will be empty data!)
Demographic = space(5000) 'space() function adds space like vb6
photo=space(4000)

iRet = ReadCARD(1, 0, Demographic, photo)

If iRet = 0 Then
MsgBox Demographic
Dim bs As BinaryStream
f= SpecialFolder.desktop.Child(“photo.jpg”)
bs = BinaryStream.Create(f, true)
If bs <> Nil Then
bs.Write(photo)
bs.Close
End If
End If

The Xojo code works however upon using cstring (which in Declare Function we cannot use string) the data seems truncated because of cstring null terminated because data return in between data contains null, so the jpg is only partially extracted and not completed in xojo.

Any other method by using byte or others?
Have tried many ways but not successful.

VB 6.0 photo result (successful)
ÿØÿà JFIF H H ÿÛ C
( 1#% (:3=<9387@H@DWE78PmQW_bghg>Mqypdx\egcÿÛ C / /cB8BccccccccccccccccccccccccccccccccccccccccccccccccccÿÀ È – " ÿÄ
ÿÄ µ
*partial vb result data shown

Xojo photo result (Failed, only partial data)
ÿØÿà

Thank you.
Any help is much appreciated.

a memoryblock perhaps?

Yes, thanks already solved it! In case anyone needs the solution, this works!

Xojo Code
Declare Function ReadCARD Lib “Cardlib.dll” ( iShow As Integer, iPort As Integer, lpDemographic As cstring , lpPhoto As ptr) As Integer

Dim iRet As Integer
dim f as folderitem

Dim Demographic As cString
Dim photo As new memoryblock(4000) '(if using As string here the result will be empty data!)
Demographic = space(5000) 'space() function adds space like vb6
photo=space(4000)

iRet = ReadCARD(1, 0, Demographic, photo)

If iRet = 0 Then
MsgBox Demographic
Dim bs As BinaryStream
f= SpecialFolder.desktop.Child(“photo.jpg”)
bs = BinaryStream.Create(f, true)
If bs <> Nil Then
bs.Write(photo)
bs.Close
End If
End If

Thank you very much.