You cannot pass List<> unmanaged C ++, since it does not have access to the CLR and does not know what to do with it.
What you can do is define a structure in C ++ that matches the layout of your C # class and pass it to the exported C ++ function that expects the array. Depending on how much control you have over the definitions of C # and C ++, you can do some things to make life easier:
First, define your C # type based on the interaction:
// In C
Secondly, since C / C ++ arrays are not managed, you will need another way to determine how large it is; the easiest option is to pass the second parameter to your C ++ function, which is the length.
// In C++ extern "C" __declspec( dllexport ) void MyFunction(LONG count, Person[] people); // In C
Then you can just call this method in C #; if you already have your own populated List<Person> , you would do this:
var personsArray = persons.ToArray(); NativeMethods.MyFunction(personsArray.Length, personsArray);
source share