Marshal list of objects from VB6 to C #
I have a development that requires transferring objects between a VB6 application and a C # class library. Objects are defined in the C # class library and are used as parameters to methods exposed by other classes in the same library. All objects contain simple string / numeric properties and therefore marshaling was relatively painless.
We now have a request to pass an object containing a list of other objects. If I were coding this in VB6, I could have a class containing the collection as a member variable. In C #, I can have a class with a List member variable.
Is it possible to build a C # class in such a way that a VB6 application can populate this inner list and marshal it successfully? I don't have much experience here, but I would suggest that Id should use an array of object types.
a source to share
The options are more limited via COM than you have in C #:
-
You can't use generics (COM doesn't support this, and TLBEXP doesn't use them)
-
There is an old class ArrayList. Or an array.
-
The COM interop layer will automatically generate a COM enumerator for the C # class that implements IEnumerable (non-generic version), you can repeat it on the VB6 side with For Each.
-
Likewise, it generates an IEnumerable for a COM class that implements a COM enumerator. You can use foreach in your C # code to enumerate VB6 Collections. Choose between them depending on who is creating the collection.
a source to share