Tuesday, December 16, 2008

[vb6] Use the RtlMoveMemory API function to copy data

Certain API functions return pointers to memory, that are of little use in VB where there is no intrinsic way of handling direct memory copy or accessing the variable pointed to directly. You can use the following function to copy bytes to a VB variable:
    Private|Public Declare Sub CopyBytes Lib "kernel32" _
Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, ByVal ByteLen As Long).
If the memory address is given as the value of a variable, pass it ByVal, otherwise pass the address of a variable indirectly by passing the variable ByRef. For example, having obtained some pointer from an API function and holding that pointer in variable MyPointer:
    Dim Barray(bLen) as byte
CopyBytes Barray(0), ByVal MyPointer, bLen
You need to determine bLen - the number of bytes to copy - beforehand.

No comments:

Post a Comment