473,394 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 16 '05 #1
2 1809
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 16 '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 16 '05 #3

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

Similar topics

3
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...

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.