Martha Amer

Martha Amer

  • NA
  • 1
  • 0

Best parctise to expose jagged arrays to COM

Mar 23 2009 2:15 AM

Hello,

I have a C# class which contains a jagged array as one of its properties:

string[][] Measurements

It worked fine with .Net applications until I was asked to expose its porperties to COM applications (namely VB6 and VBScript).  I was able to expose all properties except the jagged array because there's no marshalling support for jagged arrays.  So, I've tried to change it to string[,] Measurements, but when I call it from VB6 I can't get the data in the array.  This code give wrong type error:

    For r = LBound(objCard.Measurements, 1) To UBound(objCard.Measurements, 1)

        For f = LBound(objCard.Measurements, 2) To UBound(objCard.Measurements, 2)

           sMeasurements = sMeasurements & objCard.Measurements[r, f]) & vbCrLf
        Next
    Next
   
And this code returns the data scrambled: the values in objCard.Measurements(0,0) then objCard.Measurements(1,0) etc. instead of 0,0 then 0,1 then 0, 2 etc.:

    For Each sReading In objCard.Measurements
            Debug.Print sReading
    Next

Any idea how I should declare the jagged array in the C# module and how I should call it from VB6 or VBScript?

Thanks,

 

Martha