[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
Public Declare Auto Sub CopyMemory lib "kernel32.dll" Alias "CopyMemory"(destination As IntPtr, source As IntPtr, length As UInteger)
<DllImport("kernel32.dll", SetLastError:= True, EntryPoint:= "CopyMemory")>
Public Shared Sub CopyMemory(destination As IntPtr, source As IntPtr, length As UInteger)
End Sub
None.
Do you know one? Please contribute it!
None.
Please add some!
static void Main()
{
const int size = 200;
IntPtr memorySource = Marshal.AllocHGlobal(size);
IntPtr memoryTarget = Marshal.AllocHGlobal(size);
CopyMemory(memoryTarget,memorySource,size);
}
Public Module CopyMemoryTest
Public Declare Auto Sub CopyMemory lib "kernel32.dll" Alias "CopyMemory"(destination As IntPtr, source As IntPtr, length As UInteger)
Public Sub Main(ParamArray args As String())
Dim source As Byte() = File.ReadAllBytes("C:\Windows\explorer.exe"),
destination(source.GetUpperBound(0)) As Byte,
length As UInteger = CUInt(source.Length),
sourcePtr As IntPtr = Marshal.UnsafeAddrOfPinnedElement(source, 0),
targetPtr As IntPtr = Marshal.UnsafeAddrOfPinnedElement(target, 0)
Restart:
Dim sw As Stopwatch = Stopwatch.StartNew()
CopyMemory(targetPtr, sourcePtr, length)
sw.Stop()
Console.WriteLine("Total time to copy {0:N0} bytes = {1}", new TimeSpan(sw.ElapsedTicks))
Using sha = New System.Security.Cryptography.SHA512Managed
Dim sourceChecksum = sha.ComputeHash(source), destinationCheksum = sha.ComputeHash(destination), isEquals = True
For i = 0 To sourceChecksum.GetUpperBound(0)
If sourceChecksum(i) <> destinationChecksum(i) Then
Console.WriteLine("The copy memory is bad, some of data are not copied..")
IsEquals = False
Exit For
End If
Next i
If isEquals Then Console.WriteLine("The copy memory is perfectly copy all bytes.")
End Using
Console.ReadKey().Key = ConsoleKeys.R Then
Goto Restart
End If
sw = Nothing
Erase source, destination
End Sub
End Module
//http://stackoverflow.com/questions/15975972/copy-data-from-from-intptr-to-intptr