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;
}