Newbie Problems
#7

They do now indeed because pragma pack is used. But before there was padding involved.

But even with the padding C# could still read it fine with Marshal.PtrToStructure

 

public static T ByteToType<T>(BinaryReader reader)
{
byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));

GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();

return theStructure;
}



Messages In This Thread
[No subject] - by dethunter12 - 03-27-2015, 03:30 AM
[No subject] - by Nikolee - 03-27-2015, 07:40 AM
[No subject] - by Wizatek - 03-27-2015, 10:19 AM
[No subject] - by dethunter12 - 03-27-2015, 11:57 AM
[No subject] - by Nikolee - 03-27-2015, 01:04 PM
[No subject] - by Tarissuis - 03-27-2015, 05:40 PM
[No subject] - by Wizatek - 03-27-2015, 05:54 PM
[No subject] - by Wahrheit - 03-28-2015, 05:26 PM
[No subject] - by DamonA - 03-28-2015, 05:44 PM
[No subject] - by Nikolee - 03-28-2015, 09:30 PM
[No subject] - by Wahrheit - 03-28-2015, 10:22 PM
[No subject] - by Nikolee - 03-29-2015, 09:03 AM
[No subject] - by CDWriter - 04-14-2015, 02:36 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)