By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Extract Text from External Application into C# Application.

P: 1
Hello,
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); // address of window displaying in SPY++.



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 "";
}
}

Please look at image attached.. it is showing result after extraction.
Attached Images
File Type: jpg text.jpg (24.9 KB, 122 views)
Aug 14 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.