I am converting some VBA code that uses the AccessibleChildren
method to C# but I am having some issues. The declaration looks like this:
[DllImport("oleacc.dll")]
private static extern uint AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [Out] object[] rgvarChildren, out int pcObtained);
The code that I am running looks like this:
private static object[] GetChildren(IAccessible element)
{
const int firstchild = 2;
int numChildren;
int numReturned;
numChildren = element.accChildCount;
object[] childrenArray = null;
if (numChildren > 0)
{
childrenArray = new object[numChildren];
AccessibleChildren(element, firstchild, numChildren, childrenArray, out numReturned);
}
return childrenArray;
}
The problem is that when I call this method on a valid IAccessible (like the Ribbon in Word) childrenArray[0]
is equal to null
. Anyone have any ideas? One thought I had (or at least something that doesn't make sense to me) is that the VBA code passes the first element of the array:
Private Function GetChildren _
(Element As IAccessible) _
As Variant()
Const FirstChild As Long = 0&
Dim NumChildren As Long
Dim NumReturned As Long
Dim ChildrenArray()
NumChildren = Element.accChildCount
If NumChildren > 0 Then
AccessibleChildren Element, FirstChild, NumChildren, _
ChildrenArray(0), NumReturned
End If
GetChildren = ChildrenArray
End Function
Thanks!