How to pass Array from c++ plugin to c#?

How to pass Array from c++ plugin to c#? I have tried different methods, still can’t work out. Does any one give some help?
[DllImport (“ASimplePlugin”)]
private static extern bool Get(ref Vector4[ ] ptrResultVerts, ref int resultVertLength);

Vector4 MarshalMethod (){

//IntPtr ptrResultVerts = IntPtr.Zero;

Vector4[ ] ptrTresultVerts = new Vector4 (0,0,0,0);

int resultVertLength = 0;

bool success = Get(ref ptrResultVerts, ref resultVertLength);

Vector4[ ] resultVertices = null;

if (success)
{
// Load the results into a managed array.
resultVertices = new Vector4[resultVertLength];

Marshal.Copy(ptrResultVerts
, resultVertices
, 0
, resultVertLength);
}

return resultVertices[0];

}

Even I change Vector4 to float numbers, still not works.

People usually uses strings to pass complex data. For example you can use miniJSON to parse your data.

Remember you have to use extern C to write plugins…
If you use simple data, transform it to char * , send it as char *, and get it as string.
If you use parameters to otuput data (ref, out, pointers etc…), you can use on the c++ side char *, and StringBuilder on the c# side, it works for me.

When you have you string on the c# code, you can use String.split and Int.Parse, float.Plarse to transform your string to arrays, or others…

Regards

That’s very helpful. I ll try that. Thank:smile:s kjuanlu.