ArrayPtr

引用内容 引用内容

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
            (pDest
As Any, pSrc As Any, ByVal lByteLen As Long)
Private Const VT_BYREF = &H4000&

' + ArrayPtr +++++++++++++++++++++++++++++++++++++++++++++++Rd+
' This function determines if the passed
'     array is initialized,
' and if so will return the pointer to t
'     he safearray header.
' If the array is not initialized, it wi
'     ll return zero.
' This function will work with vb5 or vb
'     6 without modification.
Public Function ArrayPtr(Arr) As Long
'     Thanks to Francesco Balena and Monte Hansen
    
Dim lpSA As Long, iDataType As Integer
    On Error GoTo
UnInit
    
' get the real VarType of the argument, this is similar to VarType(), but returns also the VT_BYREF bit
    
CopyMemory iDataType, Arr, n2
    
' if a valid array was passed
    
If (iDataType And vbArray) = vbArray Then
        
' 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.
        
CopyMemory lpSA, ByVal VarPtr(Arr) + n8, n4
        
' see whether the function was passed a Variant that contains an array, rather than directly an array in the former case ptr already points to the SA structure. Thanks to Monte Hansen.
        
If (iDataType And VT_BYREF) Then
        
' lpSA is a discripter (pointer) to the safearray structure
            
CopyMemory lpSA, ByVal lpSA, n4
        
End If
    End If
UnInit:
End Function
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



[本日志由 JiaJia 于 2008-01-24 02:50 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: VB
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.