本文整理汇总了VB.NET中System.Runtime.InteropServices.Marshal.Copy方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Marshal.Copy方法的具体用法?VB.NET Marshal.Copy怎么用?VB.NET Marshal.Copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.Marshal
的用法示例。
在下文中一共展示了Marshal.Copy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Create a managed array.
Dim managedArray As Int64() = {1, 2, 3, 4}
' Initialize unmanaged memory to hold the array.
Dim size As Integer = Marshal.SizeOf(managedArray(0)) * managedArray.Length
Dim pnt As IntPtr = Marshal.AllocHGlobal(size)
Try
' Copy the array to unmanaged memory.
Marshal.Copy(managedArray, 0, pnt, managedArray.Length)
' Copy the unmanaged array back to another managed array.
Dim managedArray2(managedArray.Length) As Int64
Marshal.Copy(pnt, managedArray2, 0, managedArray.Length)
Console.WriteLine("The array was copied to unmanaged memory and back.")
Finally
' Free the unmanaged memory.
Marshal.FreeHGlobal(pnt)
End Try
End Sub
End Module
示例2: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Create a managed array.
Dim managedArray As Integer() = {1, 2, 3, 4}
' Initialize unmanaged memory to hold the array.
Dim size As Integer = Marshal.SizeOf(managedArray(0)) * managedArray.Length
Dim pnt As IntPtr = Marshal.AllocHGlobal(size)
Try
' Copy the array to unmanaged memory.
Marshal.Copy(managedArray, 0, pnt, managedArray.Length)
' Copy the unmanaged array back to another managed array.
Dim managedArray2(managedArray.Length) As Integer
Marshal.Copy(pnt, managedArray2, 0, managedArray.Length)
Console.WriteLine("The array was copied to unmanaged memory and back.")
Finally
' Free the unmanaged memory.
Marshal.FreeHGlobal(pnt)
End Try
End Sub
End Module
示例3: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Create a managed array.
Dim managedArray As Short() = {1, 2, 3, 4}
' Initialize unmanaged memory to hold the array.
Dim size As Integer = Marshal.SizeOf(managedArray(0)) * managedArray.Length
Dim pnt As IntPtr = Marshal.AllocHGlobal(size)
Try
' Copy the array to unmanaged memory.
Marshal.Copy(managedArray, 0, pnt, managedArray.Length)
' Copy the unmanaged array back to another managed array.
Dim managedArray2(managedArray.Length) As Short
Marshal.Copy(pnt, managedArray2, 0, managedArray.Length)
Console.WriteLine("The array was copied to unmanaged memory and back.")
Finally
' Free the unmanaged memory.
Marshal.FreeHGlobal(pnt)
End Try
End Sub
End Module
示例4: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Create a managed array.
Dim managedArray As Double() = {0.1, 0.2, 0.3, 0.4}
' Initialize unmanaged memory to hold the array.
Dim size As Integer = Marshal.SizeOf(managedArray(0)) * managedArray.Length
Dim pnt As IntPtr = Marshal.AllocHGlobal(size)
Try
' Copy the array to unmanaged memory.
Marshal.Copy(managedArray, 0, pnt, managedArray.Length)
' Copy the unmanaged array back to another managed array.
Dim managedArray2(managedArray.Length) As Double
Marshal.Copy(pnt, managedArray2, 0, managedArray.Length)
Console.WriteLine("The array was copied to unmanaged memory and back.")
Finally
' Free the unmanaged memory.
Marshal.FreeHGlobal(pnt)
End Try
End Sub
End Module
示例5: Module1
' Remember that the actual size of System.Char in unmanaged memory is 2.
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
' Create a managed array.
Dim managedArray As Char() = New Char(999) {}
managedArray(0) = "a"c
managedArray(1) = "b"c
managedArray(2) = "c"c
managedArray(3) = "d"c
managedArray(999) = "Z"c
' Initialize unmanaged memory to hold the array.
' Dim size As Integer = Marshal.SizeOf(managedArray[0]) * managedArray.Length; ' Incorrect
Dim size As Integer = Marshal.SystemDefaultCharSize * managedArray.Length ' Correct
Dim pnt As IntPtr = Marshal.AllocHGlobal(size)
Try
' Copy the array to unmanaged memory.
Marshal.Copy(managedArray, 0, pnt, managedArray.Length)
' Copy the unmanaged array back to another managed array.
Dim managedArray2 As Char() = New Char(managedArray.Length - 1) {}
Marshal.Copy(pnt, managedArray2, 0, managedArray.Length)
Console.WriteLine("Here is the roundtripped array: {0} {1} {2} {3} {4}", managedArray2(0), managedArray2(1), managedArray2(2), managedArray2(3), managedArray2(999))
Console.WriteLine("The array was copied to unmanaged memory and back.")
Finally
' Free the unmanaged memory.
Marshal.FreeHGlobal(pnt)
End Try
End Sub
End Module
示例6: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Create a managed array.
Dim managedArray As Byte() = {1, 2, 3, 4}
' Initialize unmanaged memory to hold the array.
Dim size As Integer = Marshal.SizeOf(managedArray(0)) * managedArray.Length
Dim pnt As IntPtr = Marshal.AllocHGlobal(size)
Try
' Copy the array to unmanaged memory.
Marshal.Copy(managedArray, 0, pnt, managedArray.Length)
' Copy the unmanaged array back to another managed array.
Dim managedArray2(managedArray.Length) As Byte
Marshal.Copy(pnt, managedArray2, 0, managedArray.Length)
Console.WriteLine("The array was copied to unmanaged memory and back.")
Finally
' Free the unmanaged memory.
Marshal.FreeHGlobal(pnt)
End Try
End Sub
End Module