VB.NET用Marshal.PtrToStructure 方法实现数据在数组和结构间复制
2013-03-20 13:41
971 查看
Imports System Imports System.Runtime.InteropServices Public Structure Point Public x As Integer Public y As Integer End Structure Module Example Sub Main() ' Create a point struct. Dim p As Point p.x = 1 p.y = 1 Console.WriteLine("The value of first point is " + p.x.ToString + " and " + p.y.ToString + ".") ' Initialize unmanged memory to hold the struct. Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(p)) Try ' Copy the struct to unmanaged memory. Marshal.StructureToPtr(p, pnt, False) ' Create another point. Dim anotherP As Point ' Set this Point to the value of the ' Point in unmanaged memory. anotherP = CType(Marshal.PtrToStructure(pnt, GetType(Point)), Point) Console.WriteLine("The value of new point is " + anotherP.x.ToString + " and " + anotherP.y.ToString + ".") Finally ' Free the unmanaged memory. Marshal.FreeHGlobal(pnt) End Try End Sub End Module
相关文章推荐
- Marshal类 两个方法StructureToPtr和PtrToStructure实现序列化 字节 数组 转换
- C#——Marshal.StructureToPtr方法简介
- sql复制表结构和数据的实现方法
- Marshal类的两个方法StructureToPtr和PtrToStructure实现序列化
- C#——Marshal.StructureToPtr方法简介
- Marshal类的两个方法StructureToPtr和PtrToStructure实现序列化
- VB.NET中实现控件数组的方法
- Marshal类的两个方法StructureToPtr和PtrToStructure实现序列化
- Marshal.StructureToPtr(Object, IntPtr, Boolean)[将数据从托管对象封送到非托管内存块]
- C# - Marshal.StructureToPtr方法简介
- C#——Marshal.StructureToPtr方法简介
- Marshal类的两个方法StructureToPtr和PtrToStructure实现序列化
- vb.net启动本地程序,并读入数据的实现方法
- sql复制表结构和数据的实现方法
- Marshal类的两个方法StructureToPtr和PtrToStructure实现序列化
- Marshal类的两个方法StructureToPtr和PtrToStructure实现序列化
- 数据结构之数组和字符串的反转java实现
- 分别介绍以下数据提供者连接各种数据库的方法 (vb.net)
- 在SQL Server中巧妙存储树形结构数据及ASP.Net javaScript无刷新树形GridView的实现
- mysqldump只导出表结构或只导出数据的实现方法【转】