C# List and C++ std::vector are not compatible. They are functionally equivalent but not binary compatible. To call native code from C#, you need data types that can be easily marshalled between managed and native code.
#include "stdafx.h"
#include <vector>
using namespace std;
int _stdcall fn(double list[], int length)
{
if (length < 20)
return 0;
double value = 0.f;
for (int i = 0; i < 20; i++)
{
list[i] = value;
value = value*2+1;
}
return 20;
}
</vector>
Import declared like so:
[DllImport("testFile.dll")]
public static extern int fn(double[] list, int length);
Call the function from C# like so:
double[] list = new double[20];
int length = 0;
length = fn(list, list.Length);
In this example, a return value of 0 means the list is too small.