Results 1 to 7 of 7

Thread: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,375

    [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    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 get the current IShellFolder and PIDL (PCUITEMID_CHILD) object during a 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.
    Attached Files Attached Files
    Last edited by Krool; Jul 6th, 2023 at 12:08 PM.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    I'd add that if you return S_FALSE in EnterFolder, you can skip the current folder, or return ERROR_CANCELLED to abort the entire operation. Microsoft seems to have not documented that, but I implemented those in my TLB-based version.

    One advantage of enumerating items with this method is the results are pre-sorted into Explorer's StrCmpLogicalW view.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,375

    Re: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    Quote Originally Posted by fafalone View Post
    I'd add that if you return S_FALSE in EnterFolder, you can skip the current folder, or return ERROR_CANCELLED to abort the entire operation. Microsoft seems to have not documented that, but I implemented those in my TLB-based version.

    One advantage of enumerating items with this method is the results are pre-sorted into Explorer's StrCmpLogicalW view.
    Thanks. But I added that already.
    See that in EnterFolder.
    Code:
    ByRef Result As NSWCBResultConstants)

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    My bad, I missed where that was actually being returned.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,375

    Re: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    Bugfix in the INamespaceWalkCB_InitializeProgressDialog. (only affects when providing a custom DialogTitle text)

    The string for the
    Code:
    [out] LPWSTR *ppszTitle
    is now only allocated via CoTaskMemAlloc and not CoTaskMemFree'ed anymore on object's release.
    Reason is that the INamespaceWalkCB interface will free it on their own.

    Strangely this bug didn't crash VB6 before, but only TwinBasic and VBA7..
    Last edited by Krool; Aug 20th, 2022 at 01:55 AM.

  6. #6
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    786

    Re: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    What is the purpose for this? I did set the root to "C:" and depth to 10...started it and I went away and did alot of other things but still going enumerated.

  7. #7
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: [VB6/VBA7] CNamespaceWalk (Using the INamespaceWalk interface)

    I like the automatic depth limits and how it returns the items already sorted. The main feature is being able to easily interface with a standard Windows progress dialog. But yes as a higher level method it takes longer. You asked it to enumerate 10 levels deep into the massive Windows folder; that's tens in not hundreds of thousands of files. Every one of which it's doing a bunch of high level shell stuff with. (Here's my version using oleexp)

    It does fall more under curiosity than practicality though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width