tags:

views:

131

answers:

2

I have a map (enum, vector< double >) in c++ code that I want to access from a c# application. This is legacy code, so I'm limited to using COM objects to pass information. Currently we pass in one enum at a time to c++, and get back one vector at a time as a SAFEARRAY.

I tried passing in a SAFEARRAY of enums, and returning a SAFEARRAY of SAFEARRAYs of doubles. In c#, my SAFEARRAY of SAFEARRAYs becomes a multi-dimension array, where I really want a jagged array.

  1. Is there a way to use SAFEARRAYs to produce a jagged array in c#?
  2. Are they other ways I could use to pass the vectors from the map to c#?
A: 

I wonder if you can use MC++ to handle the marshalling? Isn't a vector really just a List in .net? In MC++ you could iterate and return a List. Then just reference the MC++ assembly.

I've not done much MC++ so I cannot be sure of the above.

Preet Sangha
I wish it was a possibility, but this is a legacy application. I might be able to write a wrapper in MC++, but the data I need is stored in unmanaged c++.
JW
Yes that's what I mean. Handle the passing of data to and fro via the MC++ wrapper. I don't mean rewriting the app.
Preet Sangha
@Preet, you would need to have an extra layer in the middle, which is something that I think he is trying to avoid.
Stan R.
Yes, it is something I am trying to avoid if possible.
JW
Yes but the layer is really no more than any interop would bring into the picture.
Preet Sangha
A: 

I found how to do it. Instead of using a SAFEARRAY of SAFEARRAYs, I use a SAFEARRAY of VARIANTs. I turn each vector of doubles into a SAFEARRAY, convert the SAFEARRAY to a VARIANT, and then put the VARIANT into a SAFEARRAY that I return to c#. It produces the jagged array that I want.

JW