Skip to content

A StringBuilder buffer has been overflowed by unmanaged code.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #190537
    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

    #190550
    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)
    
    #190549
    Chike
    Member

    Try

    Dim sb As StringBuilder = New StringBuilder(iLineLength+1)
    sb.Append(ChrW(iLineLength+1))
    #190548
    pharaon
    Member

    still give me the same error

    #190547
    Chike
    Member

    Post send message declarations

    #190546
    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
    
    #190545
    Chike
    Member

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

    #190544
    pharaon
    Member

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

    #190543
    Chike
    Member

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

    #190542
    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.

    #190541
    Chike
    Member

    Yes catch it and check all relevant parameters in code.

    Try
        SendMessage(hwnd, EM_GETLINE, ilastLine, sb)
    Catch ex As Exception
        MsgBox("SendMessage failed " & ex.Message)
    End Try

    Set breakpoint at MsgBox

    #190540
    pharaon
    Member

    i did but couldn’t find any thing

    #190539
    Chike
    Member

    What all parameters ok and it fail?

    #190538
    pharaon
    Member

    yes

Viewing 14 posts - 1 through 14 (of 14 total)