0

我想设置我的编辑控件的文本。当我这样做时,新内容是中文的。

例如,这个:

[DllImport("user32.dll")]
public static extern int SendMessageW([InAttribute] System.IntPtr hWnd, int Msg, int wParam, string lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr GetFocus();

IntPtr c = GetFocus();
SendMessageW(c, 12, 0, "Test"); //Notice that 12 = WM_SETTEXT

将我的编辑控制设置为:敔瑳

4

1 回答 1

0

根据pinvoke.net,您需要MarshalAs字符串参数的属性:

[DllImport("user32.dll")]
public static extern int SendMessageW(
    [InAttribute] System.IntPtr hWnd, 
    int Msg, 
    int wParam, 
    [MarshalAs(UnmanagedType.LPWStr)] string lParam);
于 2018-07-23T14:20:12.447 回答