views:

49

answers:

1

Hello all,

I am currently in the process of designing an interface for .NET software that would be consumed by COM objects - specifically, VB6.

While I have found a number of pages by Microsoft detailing how to make an COM-interoperable interface, I am currently tripping over the use of Collections in design time: I would like to be able to use a standard VB6 "Collection object" in the .NET program - that way, I would be able to specify, in the interface, such a collection as an argument, or as a return type, simplifying the work required for clients to use the interface.

Thank you in advance.

Edit: I don't intend to use VB6 collections in the "real work" .NET program - I would convert the VB6 collections as soon as possible and call other methods using proper .NET collections.

+1  A: 

You shouldn't use a type such as the Collection Object from the Visual Basic Runtime in .NET.
Instead you should try to find an equivalent class in the System.Collections namespace that best suits your needs. Check out the following article for some guidance:

Enrico Campidoglio
Thank you for your reply. However, as I say in the post body, I want to do that in the context of defining, in .NET, an interface that would be consumed by VB6 programs. The reason for me to use VB6 collections is to make it as easy as possible for clients to use the interface, by having VB6 collections being specified in the interface as return types or as arguments.
jhominal
I understand. However the point is the you shouldn't need to do that. The COM-interop layer built into .NET will automatically translate .NET-specific types into the equivalent COM-types for you and marshal the data across the two runtimes. In your case you could for example expose arrays in your .NET interface for best interoperability.
Enrico Campidoglio
That's accurate. .NET collection classes can be iterated in VB6 code with the For Each syntax.
Hans Passant
Ok, thank you very much.
jhominal