SendMessage to Notepad++ in C#

后端 未结 1 1886
天涯浪人
天涯浪人 2021-01-20 21:52

When I try to send text from my RichTextBox to Notepad++ it only sends the first letter of the text. So if I had in my text box Send this to Notepad++ in Notepa

相关标签:
1条回答
  • 2021-01-20 22:08

    You are running into a string encoding issue. Strings in .NET are UTF-16 little-endian strings. The string "Send" in UTF-16 is actually the bytes S{0}e{0}n{0}d{0}{0}{0}. Your declaration of SendMessage is using the ANSI string method. There are a number of ways to solve this. Here's one: Explicitly use the UTF-16 form by changing SendMessage to SendMessageW.

    [DllImport("User32.dll")]
    public static extern int SendMessageW(IntPtr hWnd, int uMsg, int wParam, string lParam);
    
    0 讨论(0)
提交回复
热议问题