Passing an object array between COM and .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I'm creating a .NET dll, which I will use in VB 6. I have no problem
declaring methods, which will take a single Object, String, Integer and so on
as a parameter. I manage even to transfer arrays of Strings and integer, but
I fail to pass an array of Objects in a parameter. How do I declare a method,
where one of the parameters is an Object array, in .NET, which I will use in
VB6?
Regards
/Niklas
 
Niklas,

You should be able to declare it with the MarshalAs attribute, like
this:

void DoSomething([MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VarType.VT_DISPATCH)] ref object[] array)
{
// Do something with the array.
}

I'm not sure about the ref, you might need it for VB6 (you can try it
with and without).

Hope this helps.
 
Hi
Thank you. The VT_DISPATCH worked. The unmanaged signature looks like this
for ref:
[id(0x6002000d)]
BSTR E_a_testObj_obj_ref_att_dispatch([in, out]
SAFEARRAY(IDispatch*)* Value);
Both ByRef and ByVal worked.
Regards
/Niklas

Nicholas Paldino said:
Niklas,

You should be able to declare it with the MarshalAs attribute, like
this:

void DoSomething([MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VarType.VT_DISPATCH)] ref object[] array)
{
// Do something with the array.
}

I'm not sure about the ref, you might need it for VB6 (you can try it
with and without).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Niklas said:
Hi
I'm creating a .NET dll, which I will use in VB 6. I have no problem
declaring methods, which will take a single Object, String, Integer and so
on
as a parameter. I manage even to transfer arrays of Strings and integer,
but
I fail to pass an array of Objects in a parameter. How do I declare a
method,
where one of the parameters is an Object array, in .NET, which I will use
in
VB6?
Regards
/Niklas
 
Back
Top