Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ***********************************************************************
- ' Author : ElektroStudios
- ' Modified : 30-March-2022
- ' ***********************************************************************
- #Region " Option Statements "
- Option Strict On
- Option Explicit On
- Option Infer Off
- #End Region
- #Region " Imports "
- Imports System.IO
- Imports System.Runtime.InteropServices
- Imports DevCase.Interop.Unmanaged.Win32.Enums
- #End Region
- #Region " IFileOperation "
- ' ReSharper disable once CheckNamespace
- Namespace DevCase.Interop.Unmanaged.Win32.Interfaces
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Exposes methods to copy, move, rename, create, and delete Shell items
- ''' as well as methods to provide progress and error dialogs.
- ''' <para></para>
- ''' This interface replaces the SHFileOperation function.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <remarks>
- ''' <see href="https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifileoperation"/>
- ''' </remarks>
- ''' ----------------------------------------------------------------------------------------------------
- <ComImport>
- <Guid("947aab5f-0a5c-4c13-b4d6-4bf7836fc9f8")>
- <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
- Public Interface IFileOperation
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Enables a handler to provide status and error information for all operations
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="pfops">
- ''' Pointer to an <see cref="IFileOperationProgressSink"/> object to be used
- ''' for progress status and error notifications.
- ''' </param>
- '''
- ''' <param name="pdwCookie">
- ''' When this method returns, this parameter points to a returned token
- ''' that uniquely identifies this connection.
- ''' <para></para>
- ''' The calling application uses this token later to delete the connection
- ''' by passing it to <see cref="IFileOperation.Unadvise"/>.
- ''' <para></para>
- ''' If the call to Advise fails, this value is meaningless.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function Advise(pfops As IFileOperationProgressSink, <[Out]> ByRef pdwCookie As UInteger) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Terminates an advisory connection previously established through <see cref="IFileOperation.Advise"/>
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="dwCookie">
- ''' The connection token that identifies the connection to delete.
- ''' <para></para>
- ''' This value was originally retrieved by <see cref="IFileOperation.Advise"/> when the connection was made.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function Unadvise(dwCookie As UInteger) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Sets parameters for the current operation.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="dwOperationFlags">
- ''' Flags that control the file operation.
- ''' <para></para>
- ''' Note: If <see cref="IFileOperation.SetOperationFlags"/> function is not called,
- ''' the default flags used by the operation are:
- ''' <see cref="FileOperationFlags.AllowUndo"/> + <see cref="FileOperationFlags.NoConfirmMakeDir"/>.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function SetOperationFlags(dwOperationFlags As FileOperationFlags) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Not implemented.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="pszMessage">
- ''' Pointer to the window title. This is a null-terminated, Unicode string.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function SetProgressMessage(<MarshalAs(UnmanagedType.LPWStr)> pszMessage As String) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Specifies a dialog box used to display the progress of the operation.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="popd">
- ''' Pointer to an IOperationsProgressDialog object that represents the dialog box.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function SetProgressDialog(<MarshalAs(UnmanagedType.Interface)> popd As Object) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a set of properties and values to be set on an item or items.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="pproparray">
- ''' Pointer to an IPropertyChangeArray,
- ''' which accesses a collection of IPropertyChange objects that specify the
- ''' properties to be set and their new values.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function SetProperties(<MarshalAs(UnmanagedType.Interface)> pproparray As Object) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Sets the parent or owner window for progress and dialog windows.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="hwndParent">
- ''' A handle to the owner window of the operation. This window will receive error messages.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function SetOwnerWindow(hwndParent As UInteger) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a single item whose property values are to be set.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="psiItem">
- ''' Pointer to the item to receive the new property values.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function ApplyPropertiesToItem(psiItem As IShellItem) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a set of items for which to apply a common set of property values.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="punkItems">
- ''' Pointer to the <see cref="IUnknown"/> of the IShellItemArray,
- ''' IDataObject, or IEnumShellItems object which represents the group of items.
- ''' <para></para>
- ''' You can also point to an IPersistIDList object to represent a single item,
- ''' effectively accomplishing the same function as <see cref="IFileOperation.ApplyPropertiesToItem"/>.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function ApplyPropertiesToItems(<MarshalAs(UnmanagedType.Interface)> punkItems As Object) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a single item that is to be given a new display name.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="psiItem">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the source item.
- ''' </param>
- '''
- ''' <param name="pszNewName">
- ''' Pointer to the new display name of the item. This is a null-terminated, Unicode string.
- ''' </param>
- '''
- ''' <param name="pfopsItem">
- ''' Pointer to an <see cref="IFileOperationProgressSink"/> object to be used
- ''' for status and failure notifications.
- ''' <para></para>
- ''' If you call <see cref="IFileOperation.Advise"/> for the overall operation,
- ''' progress status and error notifications for the rename operation are included there,
- ''' so set this parameter to NULL.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function RenameItem(psiItem As IShellItem, <MarshalAs(UnmanagedType.LPWStr)> pszNewName As String, pfopsItem As IFileOperationProgressSink) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a set of items that are to be given a new display name. All items are given the same name.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="pUnkItems">
- ''' Pointer to the IUnknown of the IShellItemArray, IDataObject,
- ''' or IEnumShellItems object which represents the group of items to be renamed.
- ''' <para></para>
- ''' You can also point to an IPersistIDList object to represent a single item,
- ''' effectively accomplishing the same function as <see cref="IFileOperation.RenameItem"/>.
- ''' </param>
- '''
- ''' <param name="pszNewName">
- ''' Pointer to the new display name of the items. This is a null-terminated, Unicode string.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function RenameItems(<MarshalAs(UnmanagedType.Interface)> pUnkItems As Object, <MarshalAs(UnmanagedType.LPWStr)> pszNewName As String) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a single item that is to be moved to a specified destination.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="psiItem">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the source item.
- ''' </param>
- '''
- ''' <param name="psiDestinationFolder">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the destination folder to contain the moved item.
- ''' </param>
- '''
- ''' <param name="pszNewName">
- ''' Pointer to a new name for the item in its new location.
- ''' <para></para>
- ''' This is a null-terminated Unicode string and can be NULL.
- ''' <para></para>
- ''' If NULL, the name of the destination item is the same as the source.
- ''' </param>
- '''
- ''' <param name="pfopsItem">
- ''' Pointer to an <see cref="IFileOperationProgressSink"/> object to be used
- ''' for progress status and error notifications for this specific move operation.
- ''' <para></para>
- ''' If you call <see cref="IFileOperation.Advise"/> for the overall operation,
- ''' progress status and error notifications for the move operation are included there,
- ''' so set this parameter to NULL.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function MoveItem(psiItem As IShellItem, psiDestinationFolder As IShellItem, <MarshalAs(UnmanagedType.LPWStr)> pszNewName As String, pfopsItem As IFileOperationProgressSink) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a set of items that are to be moved to a specified destination.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="punkItems">
- ''' Pointer to the <see cref="IUnknown"/> of the IShellItemArray, IDataObject,
- ''' or IEnumShellItems object which represents the group of items to be moved.
- ''' <para></para>
- ''' You can also point to an IPersistIDList object to represent a single item,
- ''' effectively accomplishing the same function as <see cref="IFileOperation.MoveItem"/>.
- ''' </param>
- '''
- ''' <param name="psiDestinationFolder">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the destination folder to contain the moved items.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function MoveItems(<MarshalAs(UnmanagedType.Interface)> punkItems As Object, psiDestinationFolder As IShellItem) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a single item that is to be copied to a specified destination.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="psiItem">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the source item.
- ''' </param>
- '''
- ''' <param name="psiDestinationFolder">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the destination folder to contain the copy of the item.
- ''' </param>
- '''
- ''' <param name="pszCopyName">
- ''' Pointer to a new name for the item after it has been copied.
- ''' This is a null-terminated Unicode string and can be NULL.
- ''' <para></para>
- ''' If NULL, the name of the destination item is the same as the source.
- ''' </param>
- '''
- ''' <param name="pfopsItem">
- ''' Pointer to an <see cref="IFileOperationProgressSink"/> object to be used
- ''' for progress status and error notifications for this specific copy operation.
- ''' <para></para>
- ''' If you call <see cref="IFileOperation.Advise"/> for the overall operation,
- ''' progress status and error notifications for the copy operation are included there,
- ''' so set this parameter to NULL.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function CopyItem(psiItem As IShellItem, psiDestinationFolder As IShellItem, <MarshalAs(UnmanagedType.LPWStr)> pszCopyName As String, pfopsItem As IFileOperationProgressSink) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a set of items that are to be copied to a specified destination.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="punkItems">
- ''' Pointer to the <see cref="IUnknown"/> of the IShellItemArray, IDataObject,
- ''' or IEnumShellItems object which represents the group of items to be copied.
- ''' <para></para>
- ''' You can also point to an IPersistIDList object to represent a single item,
- ''' effectively accomplishing the same function as <see cref="IFileOperation.CopyItem"/>.
- ''' </param>
- '''
- ''' <param name="psiDestinationFolder">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the destination folder to contain the copy of the items.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function CopyItems(<MarshalAs(UnmanagedType.Interface)> punkItems As Object, psiDestinationFolder As IShellItem) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a single item that is to be deleted.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="psiItem">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the item to be deleted.
- ''' </param>
- '''
- ''' <param name="pfopsItem">
- ''' Pointer to an <see cref="IFileOperationProgressSink"/> object to be used
- ''' for progress status and error notifications for this specific delete operation.
- ''' <para></para>
- ''' If you call <see cref="IFileOperation.Advise"/> for the overall operation,
- ''' progress status and error notifications for the delete operation are included there,
- ''' so set this parameter to NULL.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function DeleteItem(psiItem As IShellItem, pfopsItem As IFileOperationProgressSink) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a set of items that are to be deleted.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="punkItems">
- ''' Pointer to the <see cref="IUnknown"/> of the IShellItemArray, IDataObject,
- ''' or IEnumShellItems object which represents the group of items to be deleted.
- ''' <para></para>
- ''' You can also point to an IPersistIDList object to represent a single item,
- ''' effectively accomplishing the same function as <see cref="IFileOperation.DeleteItem"/>.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function DeleteItems(<MarshalAs(UnmanagedType.Interface)> punkItems As Object) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Declares a new item that is to be created in a specified location.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="psiDestinationFolder">
- ''' Pointer to an <see cref="IShellItem"/> that specifies the destination folder that will contain the new item.
- ''' </param>
- '''
- ''' <param name="dwFileAttributes">
- ''' A bitwise value that specifies the file system attributes for the file or folder.
- ''' </param>
- '''
- ''' <param name="pszName">
- ''' Pointer to the file name of the new item, for instance Newfile.txt. This is a null-terminated, Unicode string.
- ''' </param>
- '''
- ''' <param name="pszTemplateName">
- ''' Pointer to the name of the template file (for example Excel9.xls) that the new item is based on,
- ''' stored in one of the following locations:
- ''' <para></para>
- ''' - CSIDL_COMMON_TEMPLATES. The default path for this folder is %ALLUSERSPROFILE%\Templates.
- ''' <para></para>
- ''' - CSIDL_TEMPLATES. The default path for this folder is %USERPROFILE%\Templates.
- ''' <para></para>
- ''' - %SystemRoot%\shellnew
- ''' <para></para>
- ''' This is a null-terminated, Unicode string used to specify an existing file of the same type as the new file,
- ''' containing the minimal content that an application wants to include in any new file.
- ''' <para></para>
- ''' This parameter is normally NULL to specify a new, blank file.
- ''' </param>
- '''
- ''' <param name="pfopsItem">
- ''' Pointer to an <see cref="IFileOperationProgressSink"/> object to be used
- ''' for status and failure notifications.
- ''' <para></para>
- ''' If you call <see cref="IFileOperation.Advise"/> for the overall operation,
- ''' progress status and error notifications for the creation operation are included there,
- ''' so set this parameter to NULL.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function NewItem(psiDestinationFolder As IShellItem, dwFileAttributes As FileAttributes, <MarshalAs(UnmanagedType.LPWStr)> pszName As String, <MarshalAs(UnmanagedType.LPWStr)> pszTemplateName As String, pfopsItem As IFileOperationProgressSink) As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Executes all selected operations.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' <para></para>
- ''' Note that if the operation was canceled by the user, this method can still return a success code.
- ''' <para></para>
- ''' Use the <see cref="IFileOperation.GetAnyOperationsAborted"/> function to determine if this was the case.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function PerformOperations() As HResult
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets a value that states whether any file operations initiated
- ''' by a call to <see cref="IFileOperation.PerformOperations"/> were stopped before they were complete.
- ''' <para></para>
- ''' The operations could be stopped either by user action or silently by the system.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="pfAnyOperationsAborted">
- ''' When this method returns, points to <see langword="True"/> if any file operations were
- ''' aborted before they were complete; otherwise, <see langword="False"/>.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' If this method succeeds, it returns <see cref="HResult.S_OK"/>.
- ''' Otherwise, it returns an <see cref="HResult"/> error code.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Function GetAnyOperationsAborted(<[Out]> <MarshalAs(UnmanagedType.Bool)> pfAnyOperationsAborted As Boolean) As HResult
- End Interface
- End Namespace
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement