|
-
CopyMemory, Variants and Byte Arrays
Hi All:
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...
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)
Sub Test()
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
End Sub
Any help would be appreciated.
--D
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks