Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Extract Text from External Application's Textbox(unicode) in C# application using user32.dll.

$
0
0

Hello ,

                All Great Coders, Programmers, Developers.

               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 usedRichTextBox 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); /// I am using window code which is displayed 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 "";
            }
        }

     


 


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>