0

I have written the below functions in C# (GetObjectByName and GetAccessibleChildren) by calling oleacc.dll. I am not able to understand when there is child of child items, it is not getting their name, i get the error "entry point not found" in accessibility.dll. Can someone help me what is happening, accChildCount gives the number correctly, but calling accChild[] doesnt give the child of child items.

    IntPtr vsHandle = Process.GetProcessById(vsProcessId).MainWindowHandle;
    IAccessible Paccessible = GetWindowAccessibleByHwnd(vsHandle);
    IAccessible vaccessible = GetObjectByName(Paccessible, " UTF-8");

Details of the functions is below

    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using Accessibility;
    [System.Runtime.InteropServices.DllImport("oleacc.dll", PreserveSig = false, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
    [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Interface)]

    public static extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [Out] object[] rgvarChildren, ref int pcObtained);

    public static IAccessible[] c(IAccessible accContainer)
    {
        // Get the number of child interfaces that belong to this object. 
        int childNum = 0;
        try
        {
            childNum = accContainer.accChildCount;
            Console.WriteLine("Child count is " + childNum);
        }
        catch (Exception ex)
        {
            childNum = 0;
        }

        // Get the child accessible objects. 
        IAccessible[] accObjects = new IAccessible[childNum];
        int count = 0;
        if (childNum != 0)
        {
            AccessibleChildren(accContainer, 0, childNum,
                accObjects, ref count);
        }
        return accObjects;
    }


    public static IAccessible GetObjectByName(IAccessible Parent, string Name)
    {
        // Return null if Parent is Null or not a COM Object 
        if (Parent == null || !Marshal.IsComObject(Parent))
        {
            return null;
        }

        // Return the Parent if the parent matches the name 
        if (Parent.accName[0] != null && Parent.accName[0].Equals(Name))
        {
            return Parent;
        }

        // Recursively check the child objects 
        IAccessible[] children = GetAccessibleChildren(Parent);
        foreach (IAccessible child in children)
        {

            //Console.WriteLine("Got Child as " + child.get_accName(0));
            Console.WriteLine("Name" + child.accName);
            IAccessible objAcc = GetObjectByName(child, Name);
            if (objAcc != null) return objAcc;
        }

        // If we're still here then return null  
        return null;
    }
h_curious
  • 1
  • 1
  • IAccessible is a legacy automation interface. Why don't you use UI Automation? – Simon Mourier Jul 18 '22 at 05:49
  • Thank you @SimonMourier , there is list view control in the customer application which is getting exposed properly when using MSAAA interface in AccExplorer and not in UI Automation ( in UI Automation , control remains as Pane, whereas in MSAAA, it lists down the text along with scroll bar ) , am thinking that using MSAAA ( Iaccessible) i will be able to select a text programmatically among that list and continue automation. My understanding is that i would have to implement server side provider if i had to access text in that control using UIAutomation, let me know your thoughts – h_curious Jul 18 '22 at 06:15
  • Do [Automate Office Ribbon through MSAA (CSOfficeRibbon​Accessibility)](https://github.com/microsoftarchive/msdn-code-gallery-microsoft/tree/master/OneCodeTeam/Automate%20Office%20Ribbon%20through%20MSAA%20(CSOfficeRibbon%E2%80%8BAccessibility)#description) example and the linked example in that page work for you? And you'd better try [Accessibility tools - Inspect](https://learn.microsoft.com/en-us/windows/win32/winauto/inspect-objects). – YangXiaoPo-MSFT Jul 18 '22 at 07:03
  • That seems strange that you get something with IAcc that you don't get with UIA. Have you tried Inspect from SDK and the newer https://accessibilityinsights.io/ – Simon Mourier Jul 18 '22 at 09:41

0 Answers0