using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Shell32 { /// Flags that control the walk operation. [PInvokeData("shobjidl_core.h", MSDNShortId = "164732ae-1c72-465c-a16b-a8eeaa9cc185")] [Flags] public enum NAMESPACEWALKFLAG { /// Use this value when you do not want to set any of the other flags. NSWF_DEFAULT = 0x00000000, /// /// Collect all of the items in the folder if both of these criteria are met: /// /// /// punkToWalk is a folder (IShellFolder or IShellView). /// /// /// None of the items in the folder are currently selected. /// /// /// NSWF_NONE_IMPLIES_ALL = 0x00000001, /// /// Collect all of the items in the folder if both of these criteria are met: /// /// /// punkToWalk is a folder (IShellFolder or IShellView). /// /// /// One of the items in the folder is currently selected. /// /// /// NSWF_ONE_IMPLIES_ALL = 0x00000002, /// Do not follow links (.lnk, .url, and folder shortcuts) in the recursion; instead, return them as regular items. NSWF_DONT_TRAVERSE_LINKS = 0x00000004, /// Do not collect the PIDLs of the nodes during the namespace walk. NSWF_DONT_ACCUMULATE_RESULT = 0x00000008, /// Include the contents of stream junction points in the walk. For instance, walk into the contents of a .cab file. NSWF_TRAVERSE_STREAM_JUNCTIONS = 0x00000010, /// Walk only file system nodes. NSWF_FILESYSTEM_ONLY = 0x00000020, /// Display a dialog box with a progress bar while walking the namespace. NSWF_SHOW_PROGRESS = 0x00000040, /// Return items in view order. This applies only when punkToWalk is an IShellView object. NSWF_FLAG_VIEWORDER = 0x00000080, /// Do not use the AutoPlay HIDA in the data object. This applies only when punkToWalk is an IDataObject object. NSWF_IGNORE_AUTOPLAY_HIDA = 0x00000100, /// Perform the walk asynchronously by running it on a background thread. NSWF_ASYNC = 0x00000200, /// /// Traverse links to return their targets (for .lnk, .url and folder shortcuts) but do not verify that those targets exist /// (Resolve). This is an optimization and does not affect the results except in the case where a missing or moved target could /// be found and returned. /// NSWF_DONT_RESOLVE_LINKS = 0x00000400, /// Undocumented. NSWF_ACCUMULATE_FOLDERS = 0x00000800, /// Do not maintain the sort order of the items being walked. NSWF_DONT_SORT = 0x00001000, /// Use SHCONTF_STORAGE in enumerations NSWF_USE_TRANSFER_MEDIUM = 0x00002000, /// /// For items with both SFGAO_FOLDER and SFGAO_STREAM passed to the walk (as opposed to those discovered by walking), for example /// .zip, .search-ms and .library-ms files do not traverse them, instead treat them as items. this will result in FoundItem() /// callbacks instead of EnterFolder()/LeaveFolder() /// NSWF_DONT_TRAVERSE_STREAM_JUNCTIONS = 0x00004000, /// Introduced in Windows 8. NSWF_ANY_IMPLIES_ALL = 0x00008000, // For selections > 0 } /// /// Exposes methods that walk a namespace from a given root node. The depth of the walk is specified and an optional array is /// returned containing the IDs of all nodes walked. /// /// /// /// Use this interface to display or perform an operation on the contents of the namespace. INamespaceWalk allows retrieval of /// all reachable nodes of your namespace as pointers to item identifier lists (PIDLs), which can in turn be used to retrieve the /// IShellFolder object for each. /// /// /// The class identifier (CLSID) for the default implementation of INamespaceWalk is CLSID_NamespaceWalker. You can obtain an /// INamespaceWalk object by creating a single uninitialized object of the class associated with CLSID_NamespaceWalker using /// CoCreateInstance. This interface's IID is IID_INamespaceWalk. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-inamespacewalk [PInvokeData("shobjidl_core.h", MSDNShortId = "164732ae-1c72-465c-a16b-a8eeaa9cc185")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("57ced8a7-3f4a-432c-9350-30f24483f74f"), CoClass(typeof(NamespaceWalker))] public interface INamespaceWalk { /// Initiates a recursive walk of the namespace from the specified root to the given depth. /// /// Type: IUnknown* /// The root node from which to begin the walk. This can be represented by one of the following objects. /// /// /// IShellFolder /// /// /// IDataObject /// /// /// IParentAndItem /// /// /// IEnumFullIDList /// /// /// IShellItem /// /// /// IShellItemArray /// /// /// IShellView /// /// /// Specifying the desktop's /// IShellFolder /// as the root allows the possibility of walking the entire Windows namespace if /// cDepth /// is sufficiently large. /// /// /// Type: DWORD /// One or more of the following flags that control the walk operation. /// NSWF_DEFAULT (0x00000000) /// Use this value when you do not want to set any of the other flags. /// NSWF_NONE_IMPLIES_ALL (0x00000001) /// Collect all of the items in the folder if both of these criteria are met: /// /// /// punkToWalk is a folder (IShellFolder or IShellView). /// /// /// None of the items in the folder are currently selected. /// /// /// NSWF_ONE_IMPLIES_ALL (0x00000002) /// Collect all of the items in the folder if both of these criteria are met: /// /// /// punkToWalk is a folder (IShellFolder or IShellView). /// /// /// One of the items in the folder is currently selected. /// /// /// NSWF_DONT_TRAVERSE_LINKS (0x00000004) /// Do not follow links (.lnk, .url, and folder shortcuts) in the recursion; instead, return them as regular items. /// NSWF_DONT_ACCUMULATE_RESULT (0x00000008) /// Do not collect the PIDLs of the nodes during the namespace walk. /// NSWF_TRAVERSE_STREAM_JUNCTIONS (0x00000010) /// Include the contents of stream junction points in the walk. For instance, walk into the contents of a .cab file. /// NSWF_FILESYSTEM_ONLY (0x00000020) /// Walk only file system nodes. /// NSWF_SHOW_PROGRESS (0x00000040) /// Display a dialog box with a progress bar while walking the namespace. /// NSWF_FLAG_VIEWORDER (0x00000080) /// Return items in view order. This applies only when punkToWalk is an IShellView object. /// NSWF_IGNORE_AUTOPLAY_HIDA (0x00000100) /// Do not use the AutoPlay HIDA in the data object. This applies only when punkToWalk is an IDataObject object. /// NSWF_ASYNC (0x00000200) /// Perform the walk asynchronously by running it on a background thread. /// NSWF_DONT_RESOLVE_LINKS (0x00000400) /// /// Traverse links to return their targets (for .lnk, .url and folder shortcuts) but do not verify that those targets exist /// (Resolve). This is an optimization and does not affect the results except in the case where a missing or moved target could /// be found and returned. /// /// NSWF_ACCUMULATE_FOLDERS (0x00000800) /// NSWF_DONT_SORT (0x00001000) /// Do not maintain the sort order of the items being walked. /// NSWF_USE_TRANSFER_MEDIUM (0x00002000) /// NSWF_DONT_TRAVERSE_STREAM_JUNCTIONS (0x00004000) /// NSWF_ANY_IMPLIES_ALL (0x00008000) /// Introduced in Windows 8. /// /// /// Type: int /// /// The maximum depth to descend through the namespace hierarchy. This depth is zero-based. Set to 0 to walk only the folder /// identified by punkToWalk but none of its subfolders. /// /// /// /// Type: INamespaceWalkCB* /// INamespaceWalkCB callback function used by INamespaceWalk. This parameter can be NULL. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalk-walk HRESULT Walk( IUnknown // *punkToWalk, DWORD dwFlags, int cDepth, INamespaceWalkCB *pnswcb ); [PreserveSig] HRESULT Walk([In, MarshalAs(UnmanagedType.IUnknown)] object punkToWalk, NAMESPACEWALKFLAG dwFlags, int cDepth, [In, Optional] INamespaceWalkCB pnswcb); /// Gets a list of objects found during a namespace walk initiated by INamespaceWalk::Walk. /// /// Type: UINT* /// The number of items stored in pppidl /// /// /// Type: LPITEMIDLIST** /// The address of a pointer to an array of PIDLs representing the items found during the namespace walk. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// To use INamespaceWalk::GetIDArrayResult, NSWF_DONT_ACCUMULATE_RESULT cannot be specified in the call to INamespaceWalk::Walk. /// /// /// It is the responsibility of the calling application to free this array. Call CoTaskMemFree for each PIDL as well as once for /// the array itself. /// /// Examples /// /// The following example creates the INamespaceWalk instance, begins the walk at the desktop, walks only the desktop folder and /// its immediate children, retrieves the PIDLs retrived in the walk, and frees their array. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalk-getidarrayresult HRESULT // GetIDArrayResult( UINT *pcItems, PIDLIST_ABSOLUTE **prgpidl ); [PreserveSig] HRESULT GetIDArrayResult(out uint pcItems, out InteropServices.SafeCoTaskMemHandle prgpidl); } /// /// A callback interface exposing methods used with INamespaceWalk. After performing a walk with INamespaceWalk, an /// IShellFolder object representing the walked nodes is passed to the INamespaceWalkCB methods. What those methods do with /// the information depends on the object that is implementing them. /// /// The IID for this interface is IID_INamespaceWalkCB. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-inamespacewalkcb [PInvokeData("shobjidl_core.h", MSDNShortId = "15244d6e-6cd7-4dee-8e4e-2533d5a60ae7")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("d92995f8-cf5e-4a76-bf59-ead39ea2b97e")] public interface INamespaceWalkCB { /// /// Called when an object is found in the namespace during a namespace walk. Use this method as the main action function for the /// class implementing it. Perform your actions as needed inside this method. /// /// /// Type: IShellFolder* /// A pointer to an IShellFolder object representing the folder containing the item. /// /// /// Type: PCUITEMID_CHILD /// The item's PIDL, relative to psf. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-founditem HRESULT // FoundItem( IShellFolder *psf, PCUITEMID_CHILD pidl ); [PreserveSig] HRESULT FoundItem([In] IShellFolder psf, [In] IntPtr pidl); /// /// Called when a folder is about to be entered during a namespace walk. Use this method for any initialization of the retrieved item. /// /// /// Type: IShellFolder* /// A pointer to an IShellFolder object representing the parent of the folder designated by pidl. /// /// /// Type: PCUITEMID_CHILD /// The PIDL, relative to psf, of the folder being entered. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-enterfolder HRESULT // EnterFolder( IShellFolder *psf, PCUITEMID_CHILD pidl ); [PreserveSig] HRESULT EnterFolder([In] IShellFolder psf, [In] IntPtr pidl); /// /// Called after a namespace walk through a folder. Use this method to perform any necessary cleanup following the actions /// performed by INamespaceWalkCB::EnterFolder or INamespaceWalkCB::FoundItem. /// /// /// Type: IShellFolder* /// A pointer to an IShellFolder object representing the parent of the folder designated by pidl. /// /// /// Type: PCUITEMID_CHILD /// A PIDL, relative to psf, of the folder being exited. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-leavefolder HRESULT // LeaveFolder( IShellFolder *psf, PCUITEMID_CHILD pidl ); [PreserveSig] HRESULT LeaveFolder([In] IShellFolder psf, [In] IntPtr pidl); /// /// Initializes the window title and cancel button text of the progress dialog box displayed during the namespace walk. /// /// /// Type: LPWSTR* /// /// When this method returns, contains a pointer to a null-terminated string that contains the title to be used for the dialog box. /// /// /// /// Type: LPWSTR* /// /// When this method returns, contains a pointer to a null-terminated string that contains the text displayed on the button that /// cancels the namespace walk. /// /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-initializeprogressdialog // HRESULT InitializeProgressDialog( LPWSTR *ppszTitle, LPWSTR *ppszCancel ); [PreserveSig] HRESULT InitializeProgressDialog([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszTitle, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszCancel); } /// /// Extends INamespaceWalkCB with a method that is required in order to complete a namespace walk. This method removes data collected /// during the walk. /// /// /// This interface also provides the methods of the INamespaceWalkCB interface, from which it inherits. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-inamespacewalkcb2 [PInvokeData("shobjidl_core.h", MSDNShortId = "a748083b-a99e-4015-93da-112d2950f623")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("7ac7492b-c38e-438a-87db-68737844ff70")] public interface INamespaceWalkCB2 : INamespaceWalkCB { /// /// Called when an object is found in the namespace during a namespace walk. Use this method as the main action function for the /// class implementing it. Perform your actions as needed inside this method. /// /// /// Type: IShellFolder* /// A pointer to an IShellFolder object representing the folder containing the item. /// /// /// Type: PCUITEMID_CHILD /// The item's PIDL, relative to psf. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-founditem HRESULT // FoundItem( IShellFolder *psf, PCUITEMID_CHILD pidl ); [PreserveSig] new HRESULT FoundItem([In] IShellFolder psf, [In] IntPtr pidl); /// /// Called when a folder is about to be entered during a namespace walk. Use this method for any initialization of the retrieved item. /// /// /// Type: IShellFolder* /// A pointer to an IShellFolder object representing the parent of the folder designated by pidl. /// /// /// Type: PCUITEMID_CHILD /// The PIDL, relative to psf, of the folder being entered. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-enterfolder HRESULT // EnterFolder( IShellFolder *psf, PCUITEMID_CHILD pidl ); [PreserveSig] new HRESULT EnterFolder([In] IShellFolder psf, [In] IntPtr pidl); /// /// Called after a namespace walk through a folder. Use this method to perform any necessary cleanup following the actions /// performed by INamespaceWalkCB::EnterFolder or INamespaceWalkCB::FoundItem. /// /// /// Type: IShellFolder* /// A pointer to an IShellFolder object representing the parent of the folder designated by pidl. /// /// /// Type: PCUITEMID_CHILD /// A PIDL, relative to psf, of the folder being exited. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-leavefolder HRESULT // LeaveFolder( IShellFolder *psf, PCUITEMID_CHILD pidl ); [PreserveSig] new HRESULT LeaveFolder([In] IShellFolder psf, [In] IntPtr pidl); /// /// Initializes the window title and cancel button text of the progress dialog box displayed during the namespace walk. /// /// /// Type: LPWSTR* /// /// When this method returns, contains a pointer to a null-terminated string that contains the title to be used for the dialog box. /// /// /// /// Type: LPWSTR* /// /// When this method returns, contains a pointer to a null-terminated string that contains the text displayed on the button that /// cancels the namespace walk. /// /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb-initializeprogressdialog // HRESULT InitializeProgressDialog( LPWSTR *ppszTitle, LPWSTR *ppszCancel ); [PreserveSig] new HRESULT InitializeProgressDialog([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszTitle, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszCancel); /// Removes data collected during a namespace walk. /// /// Type: HRESULT /// The results of Walk. /// /// /// Type: HRESULT /// Always returns S_OK. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-inamespacewalkcb2-walkcomplete HRESULT // WalkComplete( HRESULT hr ); [PreserveSig] HRESULT WalkComplete(HRESULT hr); } /// CLSID_NamespaceWalker [ComImport, Guid("72eb61e0-8672-4303-9175-f2e4c68b2e7c"), ClassInterface(ClassInterfaceType.None)] public class NamespaceWalker { } } }