Results 1 to 14 of 14

Thread: Retrieving Text from an external app?

Hybrid View

  1. #1
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Retrieving Text from an external app?

    There are some problems with your EditStreamCallback Function
    The second parameter you have defined as ByVal Byte.
    It is a long pointer to a byte array so that you should either define it as
    ByVal pbBuff as Long
    or
    pbBuff() as Byte
    If you choose the second option you can form your string like this
    VB Code:
    1. dim i as integer, myStr as String
    2. myStr=""
    3. for i=0 to cb-1
    4.   myStr = myStr & chr(pbBuff(i))
    5. next i
    Try that

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Retrieving Text from an external app?

    Thanks, moeur, at least you know what you're doing

    Made a couple of mistakes in my code (obviously)

    In the form code
    Code:
        If (udtStreamInfo.dwError) Then
            MsgBox "Error ID " & udtStreamInfo.dwError & " occured", vbExclamation
        
          Else  ' If there was no error,
            ' copy the contents of the buffer into
            ' the RTF Edit control
            rtfText.TextRTF = gstrBuffer
        End If
    should be
    Code:
        If (udtStreamInfo.dwError) Then
            MsgBox "Error ID " & udtStreamInfo.dwError & " occured", vbExclamation
        End If
    and in the module code, as moeur pointed out
    Code:
    Public Function EditStreamCallBack(ByVal dwCookie As Long, _
                                             pbBuff() As Byte, _
                                       ByVal cb As Long, _
                                       ByRef pcb As Long) _
    As Long    '{
    
        ' pbBuff = pointer to byte array (thanks moeur :)
        Dim strBuffer       As String
        Dim strRTFText      As String
        Dim i               As Long
        
        ' Get the string contents
        For i = 0 To (cb - 1)
            strBuffer = strBuffer & Chr$(pbBuff(i))
        Next i
        
        ' Set the no. of bytes received
        pcb = pcb + cb
        
        ' Add buffer to text box
        strRTFText = ghTextBox.TextRTF & strBuffer
        ghTextBox.TextRTF = strRTFText
        
        ' Return zero to allow continuation of callback
        EditStreamCallBack = 0
        
    ' }
    End Function
    hope this gets a bit further

Posting Permissions

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



Click Here to Expand Forum to Full Width