Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to set the text of my Edit Control. When I do, the new content is Chinese.
For example, this:
C#
[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

sets my Edit Control to this: 敔瑳

What I have tried:

I've tried finding a solution online and asked the same Question here
Posted
Updated 23-Jul-18 4:18am
v2
Comments
Dave Kreskowiak 23-Jul-18 10:13am    
We'd need to see the rest of the relevant code, especially your definition of SendMessageW.
[no name] 23-Jul-18 10:16am    
Oops, I'm sorry, I forgot that. Now I added the definition of SendMessageW

1 solution

According to pinvoke.net[^], you need a MarshalAs attribute on the string parameter:
C#
[DllImport("user32.dll")]
public static extern int SendMessageW(
    [InAttribute] System.IntPtr hWnd, 
    int Msg, 
    int wParam, 
    [MarshalAs(UnmanagedType.LPWStr)] string lParam);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900