我正在尝试使用 C# 中的 VirtualBox COM API (VBoxC.dll)。我跑了
tlbimp VirtualBox.tlb
针对 VirtualBox SDK 中包含的类型库。引用输出程序集可以构建,但在运行时SafeArrayTypeMispatchException
,每当我尝试访问返回数组的属性时,我都会得到一个(“指定的数组不是预期的类型”)。
例如,我可以看到它IVirtualBox.get_Machines()
被定义为
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_DISPATCH)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(0x60020009)]
public virtual extern IMachine[] get_Machines();
我怎样才能正确地调用 marshall?