|
-
May 10th, 2005, 04:44 AM
#5
Frenzied Member
Re: How To Retrieve Keys from Collection?
 Originally Posted by chemicalNova
Or you could use something like this:
VB Code:
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (A As _
Any, b As Any, ByVal C As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Any) As _
Long
Public Type CollectionData
Unk0(0 To 2) As Long
Unk1 As Long
ElementCount As Long
Unk2 As Long
PtrFirstElement As Long
PtrLastElement As Long
Unk3 As Long
Unk4 As Long
Unk5 As Long
End Type
Public Type CollectionElement
Data As Variant
Key As Long
PtrPrev As Long
PtrNext As Long
Unk0 As Long
Unk1 As Long
Unk2 As Long
End Type
Function CollectionGetKeys(ByVal Col As Collection) As String()
Dim asKeys() As String
Dim lIdx As Long
Dim tColl As CollectionData
Dim tColElem As CollectionElement
If Col.Count > 0 Then
ReDim asKeys(1 To Col.Count)
MoveMemory tColl, ByVal ObjPtr(Col), LenB(tColl)
tColElem.PtrNext = tColl.PtrFirstElement
For lIdx = 1 To tColl.ElementCount
MoveMemory tColElem, ByVal tColElem.PtrNext, LenB(tColElem)
asKeys(lIdx) = pvPtr2Str(tColElem.Key)
Next
End If
CollectionGetKeys = asKeys
End Function
Function pvPtr2Str(lpszA As Long) As String
pvPtr2Str = String$(lstrlenW(lpszA), 0)
MoveMemory ByVal StrPtr(pvPtr2Str), ByVal lpszA, lstrlenW(lpszA) * 2
End Function
..it can cause problems though. I'm not sure I've done it correctly. But it will return the keys you want.
chem
Chem.. y would one want to use this way as there are a lot of easier options (like creating custom class or using Dictionary object)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|