This project is intended to demonstrate how to implement the INamespaceWalk interface.
It uses lightweight COM and no .tlb is required and no VTable subclassing is used.
This means that the source files are self-sufficient.
Also everything is PtrSafe so it can work in VB6 or VBA7 in 32-bit or 64-bit environment.
The INamespaceWalk interface is a fast approach to enumerate folders and files.
CNamespaceWalk
The main creatable class.
Object: Returns the own instance.
RootFolder: Returns/sets the root folder from which to begin the namespace walk. (Default)
Flags: Returns/sets the options for a namespace walk.
Levels: Returns/sets the maximum depth to descend through the namespace hierarchy.
Walk(Optional ByVal Callback As INamespaceWalkCB) As Boolean: Initiates a recursive walk of the namespace from the specified root folder.
GetIDArrayResult() As CNSWIDArrayResult: Gets an array of PIDL objects found during a namespace walk.
CNSWIDArrayResult
Helper class object to hold PIDL (PCIDLIST_ABSOLUTE) objects from calling GetIDArrayResult in CNamespaceWalk.
All objects will be freed automatically upon Class_Terminate.
The Count property will be 0 if the flag 'NSWDontAccumulateResult' was set prior to the Walk.
Object: Returns the own instance.
LpIDList: Returns a pointer to a PIDL object given its index. (Default)
GetPathFromIDList(ByVal Index As Long) As String: Converts a PIDL object to a file system path given its index.
Count: Returns the number of PIDL objects.
INamespaceWalkCB
Optional callback interface which needs to be implemented on the object that will be passed to the Walk method in CNamespaceWalk as an optional argument.
FoundItem(ByVal Item As INSWCBObject): Interface method when an object is found during a namespace walk.
EnterFolder(ByVal Folder As INSWCBObject, ByRef Result As NSWCBResultConstants): Interface method when a folder is about to be entered during a namespace walk.
LeaveFolder(ByVal Folder As INSWCBObject): Interface method after a namespace walk through a folder.
InitializeProgressDialog(ByRef DialogTitle As String): Interface method to initializes the caption of the progress dialog box displayed during a namespace walk.
WalkComplete(ByVal HResult As Long): Interface method when a namespace walk has been completed or canceled. Use this method to perform any necessary cleanup.
INSWCBObject
Helper interface to hold the current IShellFolder and PIDL (PCUITEMID_CHILD) object during the callback at INamespaceWalkCB.
LpIShellFolder: Interface method to return a pointer to an IShellFolder object.
LpIDList: Interface method to return a pointer to a PIDL object.
GetDisplayNameOf() As String: Support IShellFolder::GetDisplayNameOf (Using SHGDN_FORPARSING)
In the attachment is the demo project included.
The source code of the project can also be viewed on GitHub.
It uses lightweight COM and no .tlb is required and no VTable subclassing is used.
This means that the source files are self-sufficient.
Also everything is PtrSafe so it can work in VB6 or VBA7 in 32-bit or 64-bit environment.
The INamespaceWalk interface is a fast approach to enumerate folders and files.
CNamespaceWalk
The main creatable class.
Object: Returns the own instance.
RootFolder: Returns/sets the root folder from which to begin the namespace walk. (Default)
Flags: Returns/sets the options for a namespace walk.
Levels: Returns/sets the maximum depth to descend through the namespace hierarchy.
Walk(Optional ByVal Callback As INamespaceWalkCB) As Boolean: Initiates a recursive walk of the namespace from the specified root folder.
GetIDArrayResult() As CNSWIDArrayResult: Gets an array of PIDL objects found during a namespace walk.
CNSWIDArrayResult
Helper class object to hold PIDL (PCIDLIST_ABSOLUTE) objects from calling GetIDArrayResult in CNamespaceWalk.
All objects will be freed automatically upon Class_Terminate.
The Count property will be 0 if the flag 'NSWDontAccumulateResult' was set prior to the Walk.
Object: Returns the own instance.
LpIDList: Returns a pointer to a PIDL object given its index. (Default)
GetPathFromIDList(ByVal Index As Long) As String: Converts a PIDL object to a file system path given its index.
Count: Returns the number of PIDL objects.
INamespaceWalkCB
Optional callback interface which needs to be implemented on the object that will be passed to the Walk method in CNamespaceWalk as an optional argument.
FoundItem(ByVal Item As INSWCBObject): Interface method when an object is found during a namespace walk.
EnterFolder(ByVal Folder As INSWCBObject, ByRef Result As NSWCBResultConstants): Interface method when a folder is about to be entered during a namespace walk.
LeaveFolder(ByVal Folder As INSWCBObject): Interface method after a namespace walk through a folder.
InitializeProgressDialog(ByRef DialogTitle As String): Interface method to initializes the caption of the progress dialog box displayed during a namespace walk.
WalkComplete(ByVal HResult As Long): Interface method when a namespace walk has been completed or canceled. Use this method to perform any necessary cleanup.
INSWCBObject
Helper interface to hold the current IShellFolder and PIDL (PCUITEMID_CHILD) object during the callback at INamespaceWalkCB.
LpIShellFolder: Interface method to return a pointer to an IShellFolder object.
LpIDList: Interface method to return a pointer to a PIDL object.
GetDisplayNameOf() As String: Support IShellFolder::GetDisplayNameOf (Using SHGDN_FORPARSING)
In the attachment is the demo project included.
The source code of the project can also be viewed on GitHub.