I have developed an Application in C# which extract text from external application's textbox , I am using user32.dll, The application is working fine but my problem is this - The external application's textbox contains text in unicode format, so whenever I extract text in my application it shows "??????" text. I have tried setting charset.unicode , and also used RichTextBox to show text in my application. Please let me know how to exract unicode text from external application.
Here is code I am using
private void button1_Click(object sender, EventArgs e)
{ IntPtr MytestHandle = new IntPtr(0x00060342);
HandleRef hrefHWndTarget = new HandleRef(null, MytestHandle);
// encode text into
richTextBox1.Text = ModApi.GetText(hrefHWndTarget.Handle);
}
public static class ModApi
{
[DllImport("user32.dll", EntryPoint = "SendMessageTimeout", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint SendMessageTimeoutText(IntPtr hWnd, int Msg, int countOfChars, StringBuilder text, uint flags, uint uTImeoutj, uint result);
public static string GetText(IntPtr hwnd)
{
var text = new StringBuilder(1024);
if (SendMessageTimeoutText(hwnd, 0xd, 1024, text, 0x2, 1000, 0) != 0)
{
return text.ToString();
}
MessageBox.Show(text.ToString());
return "";
}
}