Casting managed byte [] to struct []
See the question and my original answer on StackOverflowIt's easier to redefine the p/invoke signature, in this case like this:
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
private static extern void CopyMemory([In, Out] byte[] pdst, Mystruct[] psrc, int cb);
define the struct layout for p/invoke:
[StructLayout(LayoutKind.Sequential)]
public struct MyStruct { public float Value; public TimeSpan Value;}
Then you can just use it like this:
CopyMemory(bufferTarget, bufferSource, bufferTarget.Length);