std vector of structs to System array & vice versa

1) given an unmanaged struct:

struct NativeStruct
  int i;
  char s[10];

and a managed struct:

public value struct ManagedStruct
  int i;
  [MarshalAs(UnmanagedType::ByValTStr), SizeConst=10] String^ s;

How to convert from

array<ManagedStrcut>^ arr 


std::vector<NativeStrcut> vec;

and vice versa: vector to system array?

2) Same question when Native struct contains these two additional fields:

short *spElements;
int sp_length; // number of elements

and managed struct:

IntPtr ipElements;
int sp_length; // number of elements

Source: .net

Leave a Reply