0

我正在将一些使用该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

谢谢!

4

1 回答 1

0

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

于 2013-09-30T19:07:04.813 回答