AccessibleChildren返回null

时间:2013-09-27 22:47:51

标签: c# vba iaccessible

我正在将一些使用AccessibleChildren方法的VBA代码转换为C#,但我遇到了一些问题。声明如下:

[DllImport("oleacc.dll")]
    private static extern uint AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [Out] object[] rgvarChildren, out int pcObtained);

我正在运行的代码如下所示:

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

问题在于,当我在有效的IAccessible上调用此方法时(如Word中的功能区)childrenArray[0]等于null。有人有主意吗?我有一个想法(或者至少对我来说没有意义的东西)是VBA代码传递数组的第一个元素:

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

谢谢!

1 个答案:

答案 0 :(得分:0)

显然0&是表示数字0的32位long的一种方式。我不确定为什么我认为这是2但是将其切换为0似乎解决了它!