我要设置“编辑控件”的文本。当我这样做时,新内容是中文。
例如,此:
[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
将我的编辑控件设置为此:敔瑳
答案 0 :(得分: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);