Marshaling Arrays from VB.NET to COM Object
I have a VB6 program that calls a COM method passing 2 arrays as parameters and expecting 2 arrays to be populated in response.
The code is where ItemID and ItemClientHandles are input array parameters, and MyItemServerHandles and errors are populated with a COM object.
Dim ItemIDs(2) As String
Dim ItemClientHandles(2) As Long
Dim Errors() As Long ' Array for returned Item related errors
Dim MyItemServerHandles() As Long ' Server Handles for Items
ItemIDs(1) = "2,VW1000,word"
ItemIDs(2) = "2,VW1002,word"
ItemClientHandles(1) = 1
ItemClientHandles(2) = 2
Call MyItems.AddItems(2, ItemIDs, ItemClientHandles, MyItemServerHandles, Errors)
Now I would like to call the same method from VB.NET and tried something like this to define arrays:
<MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I4, SizeConst:=2)> Private MyItemServerHandles(2) As Int32 ' Server Handles for Items
<MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.LPWStr, SizeConst:=2)> Private ItemIDs(2) As String
<MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I4, SizeConst:=2)> Private ItemClientHandles(2) As Int32
<MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I4, SizeConst:=2)> Dim Errors(2) As Int32 ' Array for returned Item related errors
but can't get it to work because i get an error (which i'm trying to translate from italian):
Can't throw objects of type 'System.Int32 [*]' to input 'System.Int32 []'
What is the correct way to dump arrays from managed VB.NET code into unmanaged COM code?
thanks
+1
a source to share