473,385 Members | 1,642 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,385 software developers and data experts.

C# COM server and array of VARIANTs

Hi,

I'm a complete newbie to .NET and C#. In the project that I'm working on, I
have a need to create a C# COM server (and for which I've referred to MSDN
samples). This COM server should pass an array of VARIANTs to a VB 6.0
client. The types of the array elements are not the same, for eg some are
string and others int, etc.

From my preliminary investigation I've found that there is no VARIANT type
in C#, so is there any other way to send across a heterogenous array to the
VB client, keeping marshaling issues in mind?

I would later want to send a 2D array across, so I would want an extendable
solution, if possible.

TIA,
SD
Apr 17 '07 #1
2 7454
SD,

If you need to eventually send across a 2D array, you should probably
return object, and then in your method, assign the return value an array of
objects. This way, the signature of the method does not change when you
have to change the output of the method (although I think that you should
have two different methods with different return types, personally).

If you set the return type to object, then COM interop will export that
as a VARIANT return type. You could set the return type to an array of
objects, which will then be exported as an array of variants, but given that
I don't know if your variant array is going to be a jagged array or not, its
safer to just create a second method, or to have the return type be of type
object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SD" <SD@discussions.microsoft.comwrote in message
news:A8**********************************@microsof t.com...
Hi,

I'm a complete newbie to .NET and C#. In the project that I'm working on,
I
have a need to create a C# COM server (and for which I've referred to MSDN
samples). This COM server should pass an array of VARIANTs to a VB 6.0
client. The types of the array elements are not the same, for eg some are
string and others int, etc.

From my preliminary investigation I've found that there is no VARIANT
type
in C#, so is there any other way to send across a heterogenous array to
the
VB client, keeping marshaling issues in mind?

I would later want to send a 2D array across, so I would want an
extendable
solution, if possible.

TIA,
SD

Apr 17 '07 #2
Yes, I will have 2 separate methods. I'm trying to do them one by one.

Just another doubt. Is this the correct way to pass a VARIANT and a VARIANT
array in the method shown below:

public interface IMyInterface
{
void TestVariantPassing( [In] Object tagVariant,
[Out, MarshalAs(
UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_VARIANT )] out Object[] pVariantArray );
}

TIA,
SD
"Nicholas Paldino [.NET/C# MVP]" wrote:
SD,

If you need to eventually send across a 2D array, you should probably
return object, and then in your method, assign the return value an array of
objects. This way, the signature of the method does not change when you
have to change the output of the method (although I think that you should
have two different methods with different return types, personally).

If you set the return type to object, then COM interop will export that
as a VARIANT return type. You could set the return type to an array of
objects, which will then be exported as an array of variants, but given that
I don't know if your variant array is going to be a jagged array or not, its
safer to just create a second method, or to have the return type be of type
object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SD" <SD@discussions.microsoft.comwrote in message
news:A8**********************************@microsof t.com...
Hi,

I'm a complete newbie to .NET and C#. In the project that I'm working on,
I
have a need to create a C# COM server (and for which I've referred to MSDN
samples). This COM server should pass an array of VARIANTs to a VB 6.0
client. The types of the array elements are not the same, for eg some are
string and others int, etc.

From my preliminary investigation I've found that there is no VARIANT
type
in C#, so is there any other way to send across a heterogenous array to
the
VB client, keeping marshaling issues in mind?

I would later want to send a 2D array across, so I would want an
extendable
solution, if possible.

TIA,
SD


Apr 18 '07 #3

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

Similar topics

4
by: Stephen Williams | last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere between 5 and 20. What I want to do is write a function that returns the captions of every ticked tick box in an array...
20
by: Pavel Stehule | last post by:
Hello, Is possible merge two arrays like array + array => array select array_append(array, array); ERROR: function array_append(integer, integer) does not exist
16
by: herbertF | last post by:
Hi guys, In a program (not my own) I encountered the declaration of a constant pointer to an array consisting of two other const pointers to arrays. Not quite sure why they do it so complicated,...
5
by: Lee | last post by:
Hi All, My problem is trying to figure out how to get the numbers from a range of cells in Excel into an array (double) in a VB.NET program, do something with the array, and then send it back to...
4
by: WayneM | last post by:
I have a vb6 app that uses an array of variants, like a database table that I would like to convert to vb.net. Does it make sense to use an array of objects in vb.net? Any other suggestions? ...
0
by: rolandheller | last post by:
Hello! We're currently looking at migrating some of our code to .NET. Our old application written in VB6 has a DLL function that passes an Array of Variants to another function. We're planning...
10
by: Raj | last post by:
I need a VB function to return array of collections like Private Type Employee empname as string address as string salary as integer deptno as integer End Type dim employees() as Employee
4
kadghar
by: kadghar | last post by:
Hi, what i need is to import a txt file or a text box with numeric values, separated by tabs, into an array. I dont want to do it by searching chr(9) and chr(10) cause this will be slow for a big...
37
by: Richard Heathfield | last post by:
candide said: They aren't. An array is an array. An address is a pointer value. These are not the same thing. If you mean that &array and &array are the same, they aren't. They have different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.