Byte array to struct
C#
1
Posts
1
Posters
0
Views
1
Watching
-
Hello, I have a structure that I want to fill with bytes from a byte array.
public struct DUMMY { public ushort dummy1; public ushort dummy2; public ushort dummy3; public ushort[] dummy4; } private byte [] filedata = new byte[512]; public void MemCopy(ref byte [] source, ref object dest) { IntPtr Ptr = Marshal.AllocHGlobal(Marshal.SizeOf(dest)); Marshal.StructureToPtr(dest, Ptr, true); int size = Marshal.SizeOf(dest); Marshal.Copy(source, 0, Ptr, size); }
I tried to do it with the MemCopy function but after the Copy dest is still empty. All I'm looking for is a c++ memcpy replacement. If possible in a Managed way. Thanks, Arjan