Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim LineCount As Integer = SendMessageINT(TextBox1.Handle, EM_GETLINECOUNT, 0, IntPtr.Zero)
Dim counter As Integer = 0
Dim LineIndex As Integer = 0
Dim lineLength As Integer
Dim curLine As String = ""
Dim stringPTR As IntPtr
For counter = 1 To LineCount - 1
'Get Index for line we want to retrieve
LineIndex = SendMessageINT(TextBox1.Handle, EM_LINEINDEX, counter, IntPtr.Zero)
'GetLineLength
lineLength = SendMessageINT(TextBox1.Handle, EM_LINELENGTH, LineIndex, IntPtr.Zero)
'Create the buffer
curLine = New String("0"c, lineLength + 2)
Mid(curLine, 1, 1) = Chr(lineLength And &HFF)
Mid(curLine, 2, 1) = Chr(lineLength \ &H100)
'Get the pointer for a buffer
stringPTR = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(curLine)
'Fill the pointer with the current line
SendMessageINT(TextBox1.Handle, EM_GETLINE, counter, stringPTR)
'Read the line
curLine = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(stringPTR)
curLine = curLine.Substring(0, lineLength)
'fill textbox2
TextBox2.Text = TextBox2.Text + curLine + vbCrLf
'clear out the space
System.Runtime.InteropServices.Marshal.FreeHGlobal(stringPTR)
stringPTR = IntPtr.Zero
Next
End Sub