ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED!)
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.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
<br />
<font face="Times"><h1>ArrayPtr function for vb5 and vb6</h1></font>
<pre><font face="Courier New" color="#0000a0">Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pDest As Any, pSrc As Any, ByVal lByteLen As Long)</font>
<font color="#008000">' + 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.</font>
<font color="#0000a0">Public Function ArrayPtr(Arr) As Long</font>
<font color="#008000"> ' Thanks to Francesco Balena and Monte Hansen</font>
<font color="#0000a0"> Dim iDataType As Integer
On Error GoTo UnInit
CopyMemory iDataType, Arr, 2&</font> <font color="#008000">' get the real VarType of the argument, this is similar to VarType(), but returns also the VT_BYREF bit</font>
<font color="#0000a0"> If (iDataType And vbArray) = vbArray Then</font> <font color="#008000">' if a valid array was passed</font>
<font color="#0000a0"> CopyMemory ArrayPtr, ByVal VarPtr(Arr) + 8&, 4&</font> <font color="#008000">' 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.</font>
<font color="#0000a0"> End If
UnInit:
End Function</font>
<font color="#008000">' ++++++++++++++++++++++++++++++++++++++</font></pre>
Original Comments (3)
Recovered from Wayback Machine