
Originally Posted by
-Franky-
My question is: How do I create a new and empty IVector_IStorageItem using your TLB?
Since IDataPackage.SetStorageItems wants only an IIterable_IStorageItem parameter and does not require a full IVector_IStorageItem implementation then the problem is simplified a lot and we can implement these IIterable interfaces in a regular cStorageItems class using a vanilla Collection object as backing storage for the vector's elements:
Code:
Class cStorageItems
Implements IIterable_IStorageItem, IIterator_IStorageItem
Private BackingStorage As Collection, m_CurrentIndex As Long
Friend Function This(vFiles As Variant) As IIterable_IStorageItem
Dim vFile As Variant
Set This = Me: If Not IsArray(vFiles) Then vFiles = Array(vFiles)
With New cAwait
For Each vFile In vFiles
If .Await(StorageFileStatics.GetFileFromPathAsync(StrRef(vFile))) = AsyncStatus_Completed Then BackingStorage.Add .GetResults(Of IStorageFile)
Next vFile
End With
End Function
Private Function IIterable_IStorageItem_First() As IIterator_IStorageItem
m_CurrentIndex = 0: Set IIterable_IStorageItem_First = Me
Debug.Print "IIterable_IStorageItem_First"
End Function
Private Property Get IIterator_IStorageItem_Current() As IStorageItem
Set IIterator_IStorageItem_Current = BackingStorage(m_CurrentIndex + 1)
Debug.Print "IIterator_IStorageItem_Current"
End Property
Private Property Get IIterator_IStorageItem_HasCurrent() As BooleanByte
IIterator_IStorageItem_HasCurrent = Abs(m_CurrentIndex <= BackingStorage.Count - 1)
Debug.Print "IIterator_IStorageItem_HasCurrent"
End Property
Private Function IIterator_IStorageItem_MoveNext() As BooleanByte
m_CurrentIndex = m_CurrentIndex + 1: IIterator_IStorageItem_MoveNext = IIterator_IStorageItem_HasCurrent
Debug.Print "IIterator_IStorageItem_MoveNext"
End Function
Private Function IIterator_IStorageItem_GetMany(ByVal Length As Long, ByVal Items As LongPtr) As Long
' Not Implemented
End Function
Private Sub Class_Initialize()
Set BackingStorage = New Collection
End Sub
End Class
As you can see the implementation is a lot simpler because these interfaces are already declared and we don't need a BAS module anymore. However we still need memory allocation for the IIterable_IStorageItem elements, hence the need for a Collection.
Here's the updated ShareUI.zip project showcasing this new approach.
I'd still go with the previous FolderLauncherOptions method of obtaining a full-fledged vector implementation as it's still a lot easier and probably performs better than a Collection (although not by much).