T
Tolga Ongunsu
I want to send the struct to another Program by using TcpClient. I found a
method that converts struct to byte but it doesnot working correctly. What
am i missing?
[StructLayout(LayoutKind.Sequential)]
public struct student
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst=33)]
public char[] sName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 33)]
public char[] sLastName;
}
private byte[] StructureToByteArray(object obj)
{
int len = Marshal.SizeOf(obj);
byte[] arr = new byte[len];
IntPtr ptr = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(obj, ptr, true);
Marshal.Copy(ptr, arr, 0, len);
Marshal.FreeHGlobal(ptr);
return arr;
}
method that converts struct to byte but it doesnot working correctly. What
am i missing?
[StructLayout(LayoutKind.Sequential)]
public struct student
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst=33)]
public char[] sName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 33)]
public char[] sLastName;
}
private byte[] StructureToByteArray(object obj)
{
int len = Marshal.SizeOf(obj);
byte[] arr = new byte[len];
IntPtr ptr = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(obj, ptr, true);
Marshal.Copy(ptr, arr, 0, len);
Marshal.FreeHGlobal(ptr);
return arr;
}