CopyMemory, Variants and Byte Arrays
Searching Deja didn't turn up anything, so I thought I'd try here.
I'm being passed a Variant which contains an array of bytes. I need to
break it into 3 pieces, looping is slow, and CopyMemory seems ideal. I
can't seem to get a pointer to the data in the variant.
The following code illustrates my problem...
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)
Dim bytSource(0 To 3) As Byte
Dim bytDest(0 To 3) As Byte
Dim varTest As Variant
'load up some test data
bytSource(0) = 0
bytSource(1) = 1
bytSource(2) = 2
bytSource(3) = 3
'this creates a variant of subtype byte array (8209 according to vartype)
varTest = bytSource
'this works just fine, you can look at the bytes in the locals window
CopyMemory bytDest(0), bytSource(0), 4
'none of the following work
CopyMemory bytDest(0), varTest(0), 4
CopyMemory bytDest(0), VarPtr(varTest(0)), 4
CopyMemory bytDest(0), ByVal (VarPtr(varTest(0))), 4
Any help would be appreciated.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center