Here’s the correct declaration of the CopyMemory API function, which is so useful whenever you want to move a block of bytes between two memory locations:
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _ source As Any, ByVal bytes As Long)
You should be aware of a few caveats of this statement:
' copy an Integer into the low word of a Long variable CopyMemory lngValue, intValue, 2
' Copy the contents of a Long variable to the memory location ' pointed to by the "address" variable Dim address As Long ... CopyMemory ByVal address, lngValue, 4
' Copy the first 1000 elements of array a() to b() ' both arrays must be of the same type, and can't be objects ' nor variable-length strings CopyMemory b(0), a(0), 1000 * Len(a(0))
If bytes > 0 Then CopyMemory source, dest, bytesEnd If