我正在将使用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
谢谢!
显然0&
是一种表示数字 0 的 32 位long
的方法。我不确定为什么我认为这是2
但将其切换到0
似乎可以解决它!