VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED)

by Rde (54 Submissions)
Category: VB function enhancement
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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.

Rate ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED)



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
' ++++++++++++++++++++++++++++++++++++++

Download this snippet    Add to My Saved Code

ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED) Comments

No comments have been posted about ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED). Why not be the first to post a comment about ArrPtr/StrArrPtr function for vb5 and vb6 (FIXED).

Post your comment

Subject:
Message:
0/1000 characters