ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED!)
![Visual Basic 6, or VB Classic Visual Basic 6, or VB Classic](https://www.fortypoundhead.com//assets/img/icons/v7/vb6.png)
This function returns a pointer to the SAFEARRAY header of any Visual Basic array, including a Visual Basic string array. Substitutes both ArrPtr and StrArrPtr. This function will work with vb5 or vb6 without modification. Normally you need to declare a VarPtr alias into msvbvm50.dll or msvbvm60.dll depending on the vb version, but this function will work with vb5 or vb6.
Original Author: Rde
Code
ArrayPtr function for vb5 and vb6
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pDest As Any, pSrc As Any, ByVal lByteLen As Long)
' + ArrayPtr ++++++++++++++++++++++++Rd+
' This function returns a pointer to the
' SAFEARRAY header of any Visual Basic
' array, including a Visual Basic string
' array.
' Substitutes both ArrPtr and StrArrPtr.
' This function will work with vb5 or
' vb6 without modification.
Public Function ArrayPtr(Arr) As Long
' Thanks to Francesco Balena and Monte Hansen
Dim iDataType As Integer
On Error GoTo UnInit
CopyMemory iDataType, Arr, 2& ' get the real VarType of the argument, this is similar to VarType(), but returns also the VT_BYREF bit
If (iDataType And vbArray) = vbArray Then ' if a valid array was passed
CopyMemory ArrayPtr, ByVal VarPtr(Arr) + 8&, 4& ' 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.
End If
UnInit:
End Function
' ++++++++++++++++++++++++++++++++++++++
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.