Page 1 of 1

GetWindowTextW get Unicode Text from another application

Posted: 26 Nov 2010, 16:31
by Rucksacktraeger
Hy guys,

I searched the internet and tried the whole last night to Get Unicode Text out of an TextBox. Because I presume that many VB6 Unicoders hang here around, I ask my question in this forum.

Well, finaly I succeeded. With the following code I can take (get and send) the Unicode Text from an hwnd (TextBox1.hwnd) to another hwnd (TextBox2.hwnd).

But when I enter instead of TextBox1.hwnd the hwnd of a textbox of any foreign aplication, it doesn't get the Text. Do you have any idea?

Code: Select all

Private Declare Function GetWindowTextUnicode Lib "user32" Alias "GetWindowTextW" (ByVal hWnd As Long, ByVal lpString As Long, ByVal cch As Long) As Long
...

Dim lLen As Long
Dim sBuf As String
Dim strW As String

    lLen = GetWindowTextLengthW(TextBox1.hWnd) + 1
    If (lLen > 1) Then
        sBuf = String$(lLen, 0)

        GetWindowTextUnicode TextBox1.hWnd, StrPtr(sBuf), lLen

        lLen = InStr(sBuf, vbNullChar)
        If lLen > 1 Then
            strW = Left$(sBuf, lLen - 1)
            SendMessageUnicode TextBox2.hWnd, WM_SETTEXT, 0, StrPtr(strW)
        End If
    End If
I have a project sample attached. There you can see that I can not get the Text of a foreign App.

I appriciate any help!

Re: GetWindowTextW get Unicode Text from another application

Posted: 26 Nov 2010, 18:20
by TiKu
Well, foreign processes have a foreign address space, but StrPtr(sBuf) is valid in your own address space only. I know that there exist solutions to this problem, but I would have to research and try myself, so I cannot give more details.

Re: GetWindowTextW get Unicode Text from another application

Posted: 27 Nov 2010, 07:22
by Rucksacktraeger
Nevermind, but thank you very much for this information! So I know what I am now searching for. Thx!

I will post a solution if I'll ever find one.