Passing an object array between COM and .NET

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top