private string CharRangeToString(CHARRANGE c) { var lParam = new TEXTRANGE(); lParam.chrg = c; //if ((c.cpMax > this.Text.Length) || ((c.cpMax - c.cpMin) <= 0)) //{ // return string.Empty; //} int size = (c.cpMax - c.cpMin) + 1; CharBuffer buffer = CharBuffer.CreateBuffer(size); IntPtr ptr = buffer.AllocCoTaskMem(); if (ptr == IntPtr.Zero) { throw new OutOfMemoryException("OutOfMemory"); } lParam.lpstrText = ptr; var num1 = (int)SendMessage(new HandleRef(this, base.Handle), 0x44b, 0, lParam); buffer.PutCoTaskMem(ptr); if (lParam.lpstrText != IntPtr.Zero) { Marshal.FreeCoTaskMem(ptr); } return(buffer.GetString()); }
internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, TEXTRANGE range);
private string CharRangeToString(CHARRANGE c) { var lParam = new TEXTRANGE(); lParam.chrg = c; //if ((c.cpMax > this.Text.Length) || ((c.cpMax - c.cpMin) <= 0)) //{ // return string.Empty; //} int size = (c.cpMax - c.cpMin) + 1; CharBuffer buffer = CharBuffer.CreateBuffer(size); IntPtr ptr = buffer.AllocCoTaskMem(); if (ptr == IntPtr.Zero) { throw new OutOfMemoryException("OutOfMemory"); } lParam.lpstrText = ptr; var num1 = (int) SendMessage(new HandleRef(this, base.Handle), 0x44b, 0, lParam); buffer.PutCoTaskMem(ptr); if (lParam.lpstrText != IntPtr.Zero) { Marshal.FreeCoTaskMem(ptr); } return buffer.GetString(); }
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TEXTRANGE lParam);
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TEXTRANGE lParam);
private static extern void RichTextBox_TextRange(out TEXTRANGE value);