I am trying to call an unmanaged function that looks like this (DATA is my C# struct):
[DllImport("data.dll")]
internal static unsafe extern int MyExternalFunction(DATA* pData, uint numElements);
This is how I'm calling the function from C#:
DATA[] data = new DATA[64];
fixed (DATA* pData = data )
{
MyExternalFunction(pData, 64);
}
[StructLayout(LayoutKind.Sequential)]
internal struct DATA
{
internal uint a;
internal uint b;
internal uint c;
internal POINT pos;
}
[StructLayout(LayoutKind.Sequential)]
internal struct POINT
{
internal int x;
internal int y;
}
Unfortunately I get this error: "Cannot marshal 'parameter #1': Pointers cannot reference marshaled structures."
If it makes any difference, my DATA struct has nested structs inside it. I have no control over how this external method is designed. What is the correct way to call this function and receive an array of structs?
DATA.