我使用这个:
原文链接:https://www.f2er.com/vb/256418.htmlPublic Declare Function GetMem4 Lib "msvbvm60" (ByVal pSrc As Long,ByVal pDst As Long) As Long Public Declare Function ArrPtr Lib "msvbvm60" Alias "VarPtr" (arr() As Any) As Long Public Function StrArrPtr(arr() As String,Optional ByVal IgnoreMe As Long = 0) As Long GetMem4 VarPtr(IgnoreMe) - 4,VarPtr(StrArrPtr) End Function Public Function UDTArrPtr(ByRef arr As Variant) As Long If VarType(arr) Or vbArray Then GetMem4 VarPtr(arr) + 8,VarPtr(UDTArrPtr) Else Err.Raise 5,"Variant must contain array of user defined type" End If End Function Public Function ArrayExists(ByVal ppArray As Long) As Long GetMem4 ppArray,VarPtr(ArrayExists) End Function
用法:
? ArrayExists(ArrPtr(someArray))
? ArrayExists(StrArrPtr(someArrayOfStrings))
? ArrayExists(UDTArrPtr(someArrayOfUDTs))