A StringBuilder buffer has been overflowed by unmanaged code.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #66700
    pharaon
    Member

    Warning: A StringBuilder buffer has been overflowed by unmanaged code.  The process may become unstable.  Insufficient capacity allocated to the StringBuilder before marshaling it.

    i get this when i get last line in chat room

    any suggestion to fix

    #66708
    pharaon
    Member

    this is the code im using

    Dim iLineIndex As Integer = SendMessage(hwnd, EM_LINEINDEX, ilastLine, 0)
    Dim iLineLength As Integer = SendMessage(hwnd, EM_LINELENGTH, iLineIndex, 0)
    if iLineLength = 0 return Nothing ' or return ""
    Dim sb As StringBuilder = New StringBuilder(iLineLength)
    sb.Append(ChrW(iLineLength))
    sb.Length = iLineLength
    SendMessage(hwnd, EM_GETLINE, ilastLine, sb)
    
    #66709
    Chike
    Administrator

    Try

    <code>Dim sb As StringBuilder = New StringBuilder(iLineLength+1)
    sb.Append(ChrW(iLineLength+1))</code>
    #66712
    pharaon
    Member

    still give me the same error

    #66714
    Chike
    Administrator

    Post send message declarations

    #66722
    pharaon
    Member
        Declare Unicode Function SendMessage Lib "USER32" Alias "SendMessageW" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As StringBuilder) As Integer
    
        Declare Auto Function SendMessage Lib "USER32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    
    #66723
    Chike
    Administrator

    Code should work, use debugger or post code example project that don’t work here

    #66724
    pharaon
    Member

    it work but some times i give me this message A StringBuilder buffer has been overflowed by unmanaged code

    #66729
    Chike
    Administrator

    I can’t debug for you, catch exception and make breakpoint there and see when it happens.

    #66731
    pharaon
    Member

    that is the exception i get

    Warning: A StringBuilder buffer has been overflowed by unmanaged code.  The process may become unstable.  Insufficient capacity allocated to the StringBuilder before marshaling it.

    #66734
    Chike
    Administrator

    Yes catch it and check all relevant parameters in code.

    <code>Try
        SendMessage(hwnd, EM_GETLINE, ilastLine, sb)
    Catch ex As Exception
        MsgBox(&quot;SendMessage failed &quot; &amp; ex.Message)
    End Try</code>

    Set breakpoint at MsgBox

    #66745
    pharaon
    Member

    i did but couldn’t find any thing

    #66747
    Chike
    Administrator

    What all parameters ok and it fail?

    #66750
    pharaon
    Member

    yes

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.