开发者

Passing c++ map data to c#

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, 开发者_Go百科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#?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜