473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing an object array between COM and .NET

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

Nov 21 '05 #1
2 3891
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]
- mv*@spam.guard.caspershouse.com

"Niklas" <Ni****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
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

Nov 21 '05 #2
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Niklas" <Ni****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
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


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14908
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
10049
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
4766
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
2
1916
by: craigkenisston | last post by:
Hi, I created an array of objects like this : object Values = {myObject.myprop, otherobject.otherprop, thirdobject.xprop}; Then I pass it to a method. and I get the values filled in that...
1
3099
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as:...
3
3773
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
3
2524
by: Stephen Travis | last post by:
I'm trying to write a subroutine that will fill an array of some type with several objects of that type. The subroutine works fine if I directly reference the array but if I pass the array as an...
2
4127
by: Neil Munro | last post by:
I'm having some "type" difficulty in passing a .NET array (byref) to a COM based API (Autodesk Inventor). In VB6 the code to return an array of tolerance values is: Dim ToleranceCount As Long...
11
8095
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
17
7211
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.