Here's what I've used for a long time (I didn't know about the Merri method)
VB Code:
Public Type SafeArray1d cDims As Integer fFeatures As Integer cbElements As Long cLocks As Long pvData As Long cElements As Long lLbound As Long End Type Public Const ARRAY_NOT_INITIALISED As Long = -1 Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, source As Any, ByVal Length As Long) Public Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long Public Function MaxOrdinal(ppSA As Long) As Long ' Eg: n = MaxOridinal(VarPtrArray(MyArray)) Dim SA As SafeArray1d Dim pSA As Long '*********************************************** '* Deref ppSA. C equivalent: = pSa=*ppSA . . . '*********************************************** CopyMemory pSA, ByVal ppSA, 4 '***************************************************** '* If we have a pointer then check to see how '* many elements we are allowed. If the array '* is not dimensioned then pSA will not be valid . . . '***************************************************** If pSA Then CopyMemory SA, ByVal pSA, LenB(SA) MaxOrdinal = (SA.cElements - 1) Else MaxOrdinal = ARRAY_NOT_INITIALISED End If End Function




Reply With Quote