README.md
December 4, 2022 ยท View on GitHub
Description
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.
More Info
| Submitted On | |
| By | Rde |
| Level | Advanced |
| User Rating | 4.7 (14 globes from 3 users) |
| Compatibility | VB 4.0 (32-bit), VB 5.0, VB 6.0 |
| Category | VB function enhancement |
| World | Visual Basic |
| Archive File |
Source 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
' ++++++++++++++++++++++++++++++++++++++