Well, it seems that your native library performs the selection, so really all you have to do is provide a pointer through which you can access the selected data.
Change the API definition to (note: I changed the maxData parameter to uint, long - 64 bits in .NET and 32 bits in native.
[DllImportAttribute("myData.dll", EntryPoint = "myData")] public static extern int myData(uint myHandle, [MarshalAs(UnmanagedType.LPTStr)] string dataName, out uint Time, out uint maxData, out IntPtr pData);
At the top of my head, I can't remember if you need the out keyword for the final parameter, but I think so.
Then call myData:
uint nAllocs = 0, time = 0; IntPtr pAllocs = IntPtr.Zero; myData(1, "description", out time, out nAllocs, out pAllocs);
Now pAllocs should point to unmanaged memory so as not to reinstall them into managed memory:
[StructLayoutAttribute(LayoutKind.Sequential, Pack = 1)] public struct DATASTRUCT { public byte Rel; public long Time; public byte Validated; public IntPtr Data;
And now you should have an array of local structures.
Note You may need to compile the project as x86 in order to standardize the IntPtr size to 4 bytes (DWORD) instead of AnyCPU by default of 8.
source share