Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return an array/list/collection of objects from C# to VB6

I am creating a COM Visible C# object to proxy calls to a webservice for VB6 application. I have a method that returns an array of objects.

public DocActionReport[] DocActionReportByDateRange(System.DateTime reportStartDate, System.DateTime reportEndDate)
{
    object[] results = this.Invoke("DocActionReportByDateRange", new object[] {
                reportStartDate,
                reportEndDate});
    return ((DocActionReport[])(results[0]));
}

When I call this method via VB6, like so:

Dim proxy As New QueueMovementServiceClient.ReadQueueInfo
Dim report() As QueueMovementServiceClient.DocActionReport

report = proxy.DocActionReportByDateRange(startDate, reportEndDate)

It successfully executes (I can see that via logging on the web service) but no data is returned to the object in VB6 (LBound(report) == 0, UBound(report) == -1).

I have tried a couple of different approaches (changing the method to a void method and passing the collection in as a ref parameter) but no joy so far.

What do I need to do to return an array of objects (list, collection, whatever) to a VB6 consumer?

like image 265
Jonathan Bates Avatar asked Jul 12 '10 06:07

Jonathan Bates


People also ask

Can you make an ArrayList of objects?

Java ArrayList of Object Array If you are not sure about the type of objects in the array or you want to create an ArrayList of arrays that can hold multiple types, then you can create an ArrayList of an object array. Below is a simple example showing how to create ArrayList of object arrays in java.

How do you return an array from a list?

You can call a static method using the class name. Returning an ArrayList from a static method is simple. Create a static method with the return type as ArrayList . Create an ArrayList and instantiate it.

How do I return an ArrayList in C#?

You can just put return null; or return new ArrayList(); since it looks like you don't care with what you're gonna get with the catch. You already have a console log. Save this answer.

Does C have ArrayList?

The arraylist. c file contains an arraylist implementation. It is implemented as a dynamic array which is automatically resized as needed.


1 Answers

Here's a trick for you:

  1. Create the exact same interface with a VB6 Com Object
  2. Import that dll into .net
  3. User reflector to look at the generated interop interface, this will hopefull allow you to see what types you need to return, then again you might just get object which won't help at all.

In VB6 if my memory goes back far enough, they used something that still leave me with a nervous twitch called SAFEARRAY's.

A SAFEARRAY is probably what needs returning here, have a look at this article, I hope it helps you (its the same issue) ...

How to pass a SAFEARRAY from C# to COM

After reading about SAFEARRAY's my gut feeling is you will decide to return a string and have toJSON and fromJSON parsers on each side of the call ;)

like image 116
Introgy Avatar answered Oct 09 '22 23:10

Introgy