1

In C++ Dll I have this code:

struct Bar 
{
   std::vector<double> a;
   std::vector<double> b;
}

std::vector<Bar> t;

How can I map t to be accesible from C#.

For example, I have created this in C++ Dll

__declspec(dllexport) void ReleaseNet(std::vector<Bar> t)
{
    someObject.setData(t);
};

And from C# I need to pass data to this method.

Martin Perry
  • 9,232
  • 8
  • 46
  • 114

1 Answers1

1

I don't know whether microsoft has some kind of mapping for STL containers but generally, using STL on the api boundary is a big "no no" since your vector class might have a different size on the other side. (an example is where visual studio in debug adds a bit of data to the structure for debug purpose)

if all you want to map is a vector, then one sure thing is that a vector is a contiguous block of memory. So you could sort of treat it as an array.

Passing vector struct between C++ and C# this gives you a bit more insight.

Community
  • 1
  • 1