Esempio n. 1
0
        byte[] getBytes(tsConfig str)
        {
            int size = Marshal.SizeOf(str);

            byte[] arr = new byte[size];

            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(str, ptr, true);
            Marshal.Copy(ptr, arr, 0, size);
            Marshal.FreeHGlobal(ptr);
            return(arr);
        }
Esempio n. 2
0
        tsConfig setBytes(byte[] arr)
        {
            tsConfig str = new tsConfig();

            int    size = Marshal.SizeOf(str);
            IntPtr ptr  = Marshal.AllocHGlobal(size);

            Marshal.Copy(arr, 0, ptr, size);

            str = (tsConfig)Marshal.PtrToStructure(ptr, str.GetType());
            Marshal.FreeHGlobal(ptr);

            return(str);
        }