Example #1
0
        public void VerfiyByValDateArray()
        {
            var structure1 = new StructWithDateArray()
            {
                array = new DateTime[]
                {
                    DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now
                }
            };

            int    size   = Marshal.SizeOf(structure1);
            IntPtr memory = Marshal.AllocHGlobal(size);

            try
            {
                Marshal.StructureToPtr(structure1, memory, false);
                Marshal.StructureToPtr(structure1, memory, true);
            }
            finally
            {
                Marshal.FreeHGlobal(memory);
            }
        }
Example #2
0
        public void StructureToPtr_ByValDateArray_Success()
        {
            var structure = new StructWithDateArray()
            {
                array = new DateTime[]
                {
                    DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now
                }
            };

            int    size   = Marshal.SizeOf(structure);
            IntPtr memory = Marshal.AllocHGlobal(size);

            try
            {
                Marshal.StructureToPtr(structure, memory, false);
                Marshal.StructureToPtr(structure, memory, true);
            }
            finally
            {
                Marshal.DestroyStructure(memory, structure.GetType());
                Marshal.FreeHGlobal(memory);
            }
        }