VirtualBox COM API from C#
Posted: 2. Oct 2009, 05:49
I am trying to use the VirtualBox COM API (VBoxC.dll) from C#. I ran
against the typelib included in the VirtualBox SDK. Referencing the output assembly builds OK but at runtime I get a SafeArrayTypeMispatchException ("Specificed array was not of the expected type") whenever I try to access properties that return arrays.
I can see, for example, that IVirtualBox.get_Machines() is defined as
How can I get this call to marshall correctly?
Code: Select all
tlbimp VirtualBox.tlbI can see, for example, that IVirtualBox.get_Machines() is defined as
Code: Select all
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_DISPATCH)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(0x60020009)]
public virtual extern IMachine[] get_Machines();