Ejemplo n.º 1
0
        static public void structToByteArray(PageArrayBin bin, ref byte[] result)
        {
            int    size   = Marshal.SizeOf(bin);
            IntPtr buffer = Marshal.AllocHGlobal(size);

            result = new byte[size];

            Marshal.StructureToPtr(bin, buffer, true);
            Marshal.Copy(buffer, result, 0, size);
            Marshal.FreeHGlobal(buffer);
        }
Ejemplo n.º 2
0
        static public void byteArrayToStruct(byte[] result, ref PageArrayBin bin)
        {
            //实际大小
            int size = result.Length;
            //结构体大小
            int totalSize = Marshal.SizeOf(bin);

            IntPtr buffer = Marshal.AllocHGlobal(totalSize);

            Marshal.Copy(result, 0, buffer, size);
            bin = (PageArrayBin)Marshal.PtrToStructure(buffer, typeof(PageArrayBin));
            Marshal.FreeHGlobal(buffer);
        }