GetWindowTextW get Unicode Text from another application

The place for programming-related topics.
Post Reply
Rucksacktraeger
Lieutenant
Posts: 23
Joined: 15 Aug 2010, 08:42

GetWindowTextW get Unicode Text from another application

Post 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!
Attachments
SenderReceiver.zip
(6.86 KiB) Downloaded 531 times
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: GetWindowTextW get Unicode Text from another application

Post 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.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Rucksacktraeger
Lieutenant
Posts: 23
Joined: 15 Aug 2010, 08:42

Re: GetWindowTextW get Unicode Text from another application

Post 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.
Post Reply