Shoutbox

Active Accesibility for VB.NET - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Skype & Live Messenger (/forumdisplay.php?fid=10)
+----- Thread: Active Accesibility for VB.NET (/showthread.php?tid=76809)

Active Accesibility for VB.NET by codercode on 08-16-2007 at 11:18 AM

:DI'm trying to obtain the handle of the input box in the chat box of Windows Live Messenger 8.1 and came across Active Accessibility.

After referring to a few threads:
http://forums.fanatic.net.nz/index.php?showtopic=12039
http://shoutbox.menthix.net/showthread.php?tid=51617
http://shoutbox.menthix.net/showthread.php?tid=44...d=460252#pid460252

got the code for VB6 from here:
http://forums.fanatic.net.nz/index.php?showtopic=...hreaded&pid=104508

code:
Private Sub cmdTest_Click()
    If lstContacts.SelCount = 0 Then Exit Sub
    If lstContacts.Text = "<All>" Then
    Else
        Dim hwnd As Long
        Dim hwnd2 As Long
        hwnd = Val(Left(lstContacts.Text, InStr(lstContacts.Text, " - ") - 1))
        hwnd2 = FindWindowEx(hwnd, 0, "DirectUIHWND", vbNullString)
        Dim lngTMP As IAccessible
        Call AccessibleObjectFromWindow(hwnd2, OBJID_CLIENT, IID_IAccessible, lngTMP)
        If lngTMP Is Nothing Then
        Else
            Dim iTMP As IAccessible
            Dim lngTMP2 As Long
            Set iTMP = lngTMP.accParent
            Dim lngCount As Long
            lngCount = iTMP.accChildCount
            Dim accChildren() As Variant
            ReDim accChildren(lngCount - 1)
            Call AccessibleChildren(iTMP, 0, lngCount - 1, accChildren(0), lngTMP2)
            Dim lngCount2 As Long
            For lngCount2 = 0 To lngCount - 1
                lstIObjects.AddItem accChildren(lngCount2).accName(CHILDID_SELF) & ":" & accChildren(lngCount2).accValue(CHILDID_SELF)
                If accChildren(lngCount2).accName(CHILDID_SELF) = "Input" Then
                    accChildren(lngCount2).accValue(CHILDID_SELF) = "You see this so you know it's working!"
                End If
            Next
        End If
    End If
End Sub

But somehow this code doesn't work with WLM 8.1 so I digged around using the Inspect32 and Accexplorer32 tools from Microsoft Active Accessibility 2.0 SDK, I'm able to make it work by adding the line
code:
On Error Resume Next
at the start of the sub and changing the line
code:
Set iTMP = lngTMP.accParent
to
code:
Set iTMP = lngTMP

However, when  I try to translate the code to VB 2005 by using:
code:
Private Declare Function AccessibleObjectFromWindow Lib "oleacc" (ByVal Hwnd As Int32, _
     ByVal dwId As Int32, _
     ByRef riid As Guid, _
     <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObject As Object) As Int32

   

    Private Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As IAccessible, _
    ByVal iChildStart As Integer, _
    ByVal cChildren As Integer, _
    ByVal rgvarChildren() As Object, _
    ByVal pcObtained As Integer) As UInteger

Private Const CHILDID_SELF As Long = 0
    Private Const CHILDID_1 As Long = 1
    Private Const OBJID_CLIENT As Long = &HFFFFFFFC

code:
Dim hwnd2, hwnd As Integer
        Dim windowText As New StringBuilder(255)

        hwnd = FindWindowEx(0, 0, "IMWindowClass", vbNullString)
        hwnd2 = FindWindowEx(hwnd, 0, "DirectUIHWND", vbNullString)
        MsgBox(hwnd2)
        Dim lngTMP As Accessibility.IAccessible
        Dim ID As Int32 = 0
        Dim IID_IAcce As New Guid("618736E0-3C3D-11CF-810C-00AA00389B71")
        Call AccessibleObjectFromWindow(hwnd2, OBJID_CLIENT, IID_IAcce, lngTMP)

        If lngTMP Is Nothing Then

        Else
            Dim iTMP As Accessibility.IAccessible
            Dim lngTMP2 As Integer
            iTMP = lngTMP
            Dim lngCount As Integer
            lngCount = iTMP.accChildCount

            'it's okay up to here

            Dim Children(lngCount - 1) As Object

            Call AccessibleChildren(iTMP, 0, (lngCount - 1), Children(0), lngTMP2)

            MsgBox(lngTMP2.ToString)
            Dim lngCount2 As Integer
            For lngCount2 = 0 To lngCount - 1


                If Children(lngCount2).accName(CHILDID_SELF) = "Input" Then
                    Children(lngCount2).accValue(CHILDID_SELF) = "You see this so you know it's working!"
                End If
            Next
        End If


I get the error of "System.NullReferenceException" when trying to call "Children(lngCount2)". Upon further checking, I found that the AccessibleChildren function is not returning any value to the variable 'Children' and lngTMP2=0 (it's supposed to be 37). Does that mean the function is not working properly?

Can anybody please point out what's wrong with my code?

Thanks in advance.

:D
RE: Active Accesibility for VB.NET by codercode on 08-25-2007 at 12:48 PM

bump