ArrayPtr
作者:JiaJia 日期:2008-01-24

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pDest As Any, pSrc As Any, ByVal lByteLen As Long)
Private Const VT_BYREF = &H4000&
' + ArrayPtr +++++++++++++++++++++++++++++++++++++++++++++++Rd+
' This function determines if the passed
' array is initialized,
' and if so will return the pointer to t
' he safearray header.
' If the array is not initialized, it wi
' ll return zero.
' This function will work with vb5 or vb
' 6 without modification.
Public Function ArrayPtr(Arr) As Long
' Thanks to Francesco Balena and Monte Hansen
Dim lpSA As Long, iDataType As Integer
On Error GoTo UnInit
' get the real VarType of the argument, this is similar to VarType(), but returns also the VT_BYREF bit
CopyMemory iDataType, Arr, n2
' if a valid array was passed
If (iDataType And vbArray) = vbArray Then
' get the address of the SAFEARRAY descriptor stored in the second half of the Variant parameter that has received the array. Thanks to Francesco Balena.
CopyMemory lpSA, ByVal VarPtr(Arr) + n8, n4
' see whether the function was passed a Variant that contains an array, rather than directly an array in the former case ptr already points to the SA structure. Thanks to Monte Hansen.
If (iDataType And VT_BYREF) Then
' lpSA is a discripter (pointer) to the safearray structure
CopyMemory lpSA, ByVal lpSA, n4
End If
End If
UnInit:
End Function
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
评论: 0 | 引用: 0 | 查看次数: -
发表评论