Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
CopyMemory, as far as the Windows API is concerned, is perfectly identical to the MoveMemory function; in fact, they actually are the same function! CopyMemory moves the contents of a portion of memory from one location to another. The two locations are identified by pointers to the memory addresses. After the copy, the original contents in the source are set to zeros.
CopyMemory does not return a value.
A pointer to any variable can be automatically generated merely be passing that variable as either Destination or Source. However, if either a String or a Long holding the desired memory address is passed, the ByVal keyword must preceed it.
' This code is licensed according to the terms and conditions listed here.
' Transfer the contents of one byte array to another. After the "copy",
' the contents of the source array are set to 0.
Dim source(0 To 9) As Byte ' source array of 10 bytes
Dim target(0 To 9) As Byte ' similarly sized target array
Dim c As Integer ' counter variable
' Fill the source array with some information.
For c = 0 To 9 ' loop through each element
source(c) = c ' set each element's value to its index
Next c
' Transfer the data from the target array to the source array. Note how pointers
' are implied merely by passing the arrays as usual.
CopyMemory target(0), source(0), 10 ' copy all 10 bytes
' Verify that the contents were transfered.
For c = 0 To 9
Debug.Print target(c); ' this will now contain the information
Next c
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: July 28, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/copymemory.html