def testReadDouble(self): data = Marshal.AllocHGlobal(CPyMarshal.DoubleSize) doubleStruct = DoubleStruct(2.2e22) Marshal.StructureToPtr(doubleStruct, data, False) self.assertEquals(CPyMarshal.ReadDouble(data), 2.2e22) Marshal.FreeHGlobal(data)
def MakeItemsTablePtr(items): if not items: return IntPtr.Zero, lambda: None itemtype = items[0].__class__ typesize = Marshal.SizeOf(itemtype()) size = typesize * (len(items) + 1) tablePtr = Marshal.AllocHGlobal(size) CPyMarshal.Zero(tablePtr, size) for i, item in enumerate(items): Marshal.StructureToPtr(item, OffsetPtr(tablePtr, typesize * i), False) def dealloc(): Marshal.DestroyStructure(tablePtr, itemtype) Marshal.FreeHGlobal(tablePtr) return tablePtr, dealloc