From 2da25331d29d8b47b46d672010140a0e2b4229f8 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 11 Jan 2019 18:05:27 -0700 Subject: [PATCH] Fixed problems with some Shell interfaces --- PInvoke/Shell32/ShObjIdl.ICommDlgBrowser.cs | 92 ++++++++++++++++++---- PInvoke/Shell32/ShObjIdl.IExplorerBrowser.cs | 81 +++++++++++++++++-- .../Shell32/ShObjIdl.IExplorerPaneVisibility.cs | 3 +- PInvoke/Shell32/ShObjIdl.IFolderView.cs | 92 +++++++++++----------- PInvoke/Shell32/ShObjIdl.IServiceProvider.cs | 5 +- PInvoke/Shell32/ShObjIdl.IShellView.cs | 14 ++-- 6 files changed, 209 insertions(+), 78 deletions(-) diff --git a/PInvoke/Shell32/ShObjIdl.ICommDlgBrowser.cs b/PInvoke/Shell32/ShObjIdl.ICommDlgBrowser.cs index 9871a83a..ad11cf09 100644 --- a/PInvoke/Shell32/ShObjIdl.ICommDlgBrowser.cs +++ b/PInvoke/Shell32/ShObjIdl.ICommDlgBrowser.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; @@ -94,6 +95,9 @@ namespace Vanara.PInvoke HRESULT IncludeObject([In] IShellView ppshv, [In] PIDL pidl); } + /* + * ICommDlgBrowser2 causes grief in .NET for some reason, so it is being left out. + * /// /// Extends the capabilities of ICommDlgBrowser. This interface is exposed by the common file dialog boxes when they host a Shell /// browser. A pointer to ICommDlgBrowser2 can be obtained by calling QueryInterface on the IShellBrowser object. @@ -151,39 +155,33 @@ namespace Vanara.PInvoke [PreserveSig] HRESULT GetViewFlags(out CDB2GVF pdwFlags); } + */ /// Extends the capabilities of ICommDlgBrowser2, and used by the common file dialog boxes when they host a Shell browser. /// [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("c8ad25a1-3294-41ee-8165-71174bd01c57")] [PInvokeData("Shobjidl.h", MSDNShortId = "c9286061-8ac8-452b-9204-193bc6b571cb")] - public interface ICommDlgBrowser3 : ICommDlgBrowser + public interface ICommDlgBrowser3 //: ICommDlgBrowser // Don't derive as it seems to cause problems with memory allocations. { /// Called when a user double-clicks in the view or presses the ENTER key. /// A pointer to the view's IShellView interface. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] - new HRESULT OnDefaultCommand([In] IShellView ppshv); + HRESULT OnDefaultCommand([In] IShellView ppshv); /// Called after a state, identified by the uChange parameter, has changed in the IShellView interface. /// A pointer to the view's IShellView interface. /// Change in the selection state. This parameter can be one of the following values. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] - new HRESULT OnStateChange([In] IShellView ppshv, CDBOSC uChange); + HRESULT OnStateChange([In] IShellView ppshv, CDBOSC uChange); /// Allows the common dialog box to filter objects that the view displays. /// A pointer to the view's IShellView interface. /// A PIDL, relative to the folder, that identifies the object. /// The browser should return S_OK to include the object in the view, or S_FALSE to hide it. [PreserveSig] - new HRESULT IncludeObject([In] IShellView ppshv, [In] PIDL pidl); - - /// Called by a Shell view to notify the common dialog box hosting it that an event has occurred. - /// A pointer to the view's IShellView interface. - /// A flag that can can take one of the following two values. - /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. - [PreserveSig] - HRESULT Notify([In] IShellView ppshv, CDB2N dwNotifyType); + HRESULT IncludeObject([In] IShellView ppshv, [In] IntPtr pidl); /// Called by the Shell view to get the default shortcut menu text. /// A pointer to the view's IShellView interface. @@ -206,12 +204,12 @@ namespace Vanara.PInvoke [PreserveSig] HRESULT GetViewFlags(out CDB2GVF pdwFlags); - /// Called after a specified column is clicked in the IShellView interface. - /// A pointer to the IShellView interface of the hosted view. - /// The index of the column clicked. + /// Called by a Shell view to notify the common dialog box hosting it that an event has occurred. + /// A pointer to the view's IShellView interface. + /// A flag that can can take one of the following two values. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] - HRESULT OnColumnClicked([In] IShellView ppshv, int iColumn); + HRESULT Notify([In] IShellView ppshv, CDB2N dwNotifyType); /// Gets the current filter as a Unicode string. /// Contains a pointer to the current filter path/file as a Unicode string. @@ -220,11 +218,75 @@ namespace Vanara.PInvoke [PreserveSig] HRESULT GetCurrentFilter([MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFileSpec, int cchFileSpec); + /// Called after a specified column is clicked in the IShellView interface. + /// A pointer to the IShellView interface of the hosted view. + /// The index of the column clicked. + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PreserveSig] + HRESULT OnColumnClicked([In] IShellView ppshv, int iColumn); + /// Called after a specified preview is created in the IShellView interface. /// A pointer to the IShellView interface of the hosted view. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] HRESULT OnPreViewCreated([In] IShellView ppshv); } + + /*[ComImport, Guid("c8ad25a1-3294-41ee-8165-71174bd01c57"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface ICommDlgBrowser3 + { + // dlg1 + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT OnDefaultCommand(IntPtr ppshv); + + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT OnStateChange( + IntPtr ppshv, + CDBOSC uChange); + + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT IncludeObject( + IntPtr ppshv, + IntPtr pidl); + + // dlg2 + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT GetDefaultMenuText( + IShellView shellView, + IntPtr buffer, //A pointer to a buffer that is used by the Shell browser to return the default shortcut menu text. + int bufferMaxLength); //should be max size = 260? + + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT GetViewFlags( + [Out] out CDB2GVF pdwFlags); // CommDlgBrowser2ViewFlags + + + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT Notify( + IntPtr pshv, CDB2N notifyType); + + // dlg3 + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT GetCurrentFilter( + StringBuilder pszFileSpec, + int cchFileSpec); + + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT OnColumnClicked( + IShellView ppshv, + int iColumn); + + [PreserveSig] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + HRESULT OnPreViewCreated(IShellView ppshv); + }*/ } } \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.IExplorerBrowser.cs b/PInvoke/Shell32/ShObjIdl.IExplorerBrowser.cs index abad08e7..7af7ba0e 100644 --- a/PInvoke/Shell32/ShObjIdl.IExplorerBrowser.cs +++ b/PInvoke/Shell32/ShObjIdl.IExplorerBrowser.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Vanara.PInvoke @@ -155,7 +156,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-iexplorerbrowser [PInvokeData("shobjidl_core.h", MSDNShortId = "da2cf5d4-5a68-4d18-807b-b9d4e2712c10")] - [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("dfd3b6b5-c10c-4be9-85f6-a66969f402f6"), CoClass(typeof(ExplorerBrowser))] + [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("DFD3B6B5-C10C-4BE9-85F6-A66969F402F6"), CoClass(typeof(ExplorerBrowser))] public interface IExplorerBrowser { /// Prepares the browser to be navigated. @@ -173,7 +174,7 @@ namespace Vanara.PInvoke /// Sets the size and position of the view windows created by the browser. /// A pointer to a DeferWindowPos handle. This parameter can be NULL. /// The coordinates that the browser will occupy. - void SetRect(IntPtr phdwp, RECT rcBrowser); + void SetRect([In, Out] ref HDWP phdwp, [In] RECT rcBrowser); /// Sets the name of the property bag. /// @@ -218,7 +219,7 @@ namespace Vanara.PInvoke /// This parameter can be NULL. For more information, see Remarks. /// /// A flag that specifies the category of the pidl. This affects how navigation is accomplished. - void BrowseToIDList([In] PIDL pidl, [In] SBSP uFlags); + void BrowseToIDList([In] IntPtr pidl, [In] SBSP uFlags); /// Browses to an object. /// A pointer to an object to browse to. If the object cannot be browsed, an error value is returned. @@ -247,27 +248,91 @@ namespace Vanara.PInvoke } /// Exposes methods for notification of Explorer browser navigation and view creation events. - [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("361bbdc7-e6ee-4e13-be58-58e2240c810f"), CoClass(typeof(ExplorerBrowser))] + [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("361bbdc7-e6ee-4e13-be58-58e2240c810f")] [PInvokeData("Shobjidl.h", MSDNShortId = "802d547f-41c2-4c4a-9f07-be615d7b86eb")] public interface IExplorerBrowserEvents { /// Notifies clients of a pending Explorer browser navigation to a Shell folder. - /// A PIDL that specifies the folder. + /// + /// Type: PCIDLIST_ABSOLUTE + /// A PIDL that specifies the folder. + /// + /// + /// Type: HRESULT + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// Explorer browser calls this method before it navigates to a folder, that is, before calling + /// IExplorerBrowserEvents::OnNavigationFailed or IExplorerBrowserEvents::OnNavigationComplete. + /// + /// Returning any failure code from this method, including E_NOTIMPL, will cancel the navigation. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-iexplorerbrowserevents-onnavigationpending + // HRESULT OnNavigationPending( PCIDLIST_ABSOLUTE pidlFolder ); [PreserveSig] HRESULT OnNavigationPending([In] IntPtr pidlFolder); /// Notifies clients that the view of the Explorer browser has been created and can be modified. - /// A pointer to an IShellView. + /// + /// Type: IShellView* + /// A pointer to an IShellView. + /// + /// + /// Type: HRESULT + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// An Explorer browser calls this method to enable the client to perform any modifications to the Explorer browser view before + /// it is shown; for example, to set view modes or folder flags. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-iexplorerbrowserevents-onviewcreated + // HRESULT OnViewCreated( IShellView *psv ); [PreserveSig] HRESULT OnViewCreated([In] IShellView psv); /// Notifies clients that the Explorer browser has successfully navigated to a Shell folder. - /// A PIDL that specifies the folder. + /// + /// Type: PCIDLIST_ABSOLUTE + /// A PIDL that specifies the folder. + /// + /// + /// Type: HRESULT + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// This method is called after method IExplorerBrowserEvents::OnViewCreated, assuming a successful view creation. + /// + /// After a navigation and view creation, either IExplorerBrowserEvents::OnNavigationComplete or + /// IExplorerBrowserEvents::OnNavigationFailed is called depending on whether the destination could be navigated to. For example, + /// a failure to navigate includes a destination that is not reached either because there is no route to the path or the user has canceled. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-iexplorerbrowserevents-onnavigationcomplete + // HRESULT OnNavigationComplete( PCIDLIST_ABSOLUTE pidlFolder ); [PreserveSig] HRESULT OnNavigationComplete([In] IntPtr pidlFolder); /// Notifies clients that the Explorer browser has failed to navigate to a Shell folder. - /// A PIDL that specifies the folder. + /// + /// Type: PCIDLIST_ABSOLUTE + /// A PIDL that specifies the folder. + /// + /// + /// Type: HRESULT + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// This method is called after method IExplorerBrowserEvents::OnViewCreated, assuming a successful view creation. + /// + /// After a navigation and view creation, either IExplorerBrowserEvents::OnNavigationComplete or + /// IExplorerBrowserEvents::OnNavigationFailed is called, depending on whether the destination could be navigated to. For + /// example, a failure to navigate includes a destination that is not reached either because there is no route to the path or the + /// user has canceled. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-iexplorerbrowserevents-onnavigationfailed + // HRESULT OnNavigationFailed( PCIDLIST_ABSOLUTE pidlFolder ); [PreserveSig] HRESULT OnNavigationFailed([In] IntPtr pidlFolder); } diff --git a/PInvoke/Shell32/ShObjIdl.IExplorerPaneVisibility.cs b/PInvoke/Shell32/ShObjIdl.IExplorerPaneVisibility.cs index 95d48160..ead5b5c8 100644 --- a/PInvoke/Shell32/ShObjIdl.IExplorerPaneVisibility.cs +++ b/PInvoke/Shell32/ShObjIdl.IExplorerPaneVisibility.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Vanara.PInvoke @@ -101,7 +102,7 @@ namespace Vanara.PInvoke /// [PInvokeData("shobjidl_core.h", MSDNShortId = "6c051cdc-b7f9-48dc-ba32-38f0f1ee5fda")] [PreserveSig] - HRESULT GetPaneState(in Guid ep, ref EXPLORERPANESTATE peps); + HRESULT GetPaneState(in Guid ep, out EXPLORERPANESTATE peps); } /// Constant GUIDs used by IExplorerPaneVisibility::GetPaneState. diff --git a/PInvoke/Shell32/ShObjIdl.IFolderView.cs b/PInvoke/Shell32/ShObjIdl.IFolderView.cs index 41c02016..70979151 100644 --- a/PInvoke/Shell32/ShObjIdl.IFolderView.cs +++ b/PInvoke/Shell32/ShObjIdl.IFolderView.cs @@ -237,38 +237,38 @@ namespace Vanara.PInvoke /// Sets the selected folder's view mode. /// One of the following values from the FOLDERVIEWMODE enumeration. - void SetCurrentViewMode(FOLDERVIEWMODE ViewMode); + void SetCurrentViewMode([In] FOLDERVIEWMODE ViewMode); /// Gets the folder object. /// Reference to the desired IID to represent the folder. - /// + /// /// When this method returns, contains the interface pointer requested in . This is typically IShellFolder /// or a related interface. This can also be an IShellItemArray with a single element. - /// - [return: MarshalAs(UnmanagedType.IUnknown)] + /// + [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] object GetFolder(in Guid riid); /// Gets the identifier of a specific item in the folder view, by index. /// The index of the item in the view. - /// The address of a pointer to a PIDL containing the item's identifier information. - PIDL Item(int iItemIndex); + /// The address of a pointer to a PIDL containing the item's identifier information. + IntPtr Item([In] int iItemIndex); /// /// Gets the number of items in the folder. This can be the number of all items, or a subset such as the number of selected items. /// /// Flags from the _SVGIO enumeration that limit the count to certain types of items. /// The number of items (files and folders) displayed in the folder view. - int ItemCount(SVGIO uFlags); + int ItemCount([In] SVGIO uFlags); /// Gets the address of an enumeration object based on the collection of items in the folder view. /// _SVGIO values that limit the enumeration to certain types of items. /// Reference to the desired IID to represent the folder. - /// + /// /// When this method returns, contains the interface pointer requested in . This is typically an /// IEnumIDList, IDataObject, or IShellItemArray. If an error occurs, this value is NULL. - /// - [return: MarshalAs(UnmanagedType.IUnknown)] - object Items(SVGIO uFlags, in Guid riid); + /// + [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] + object Items([In] SVGIO uFlags, in Guid riid); /// Gets the index of an item in the folder's view which has been marked by using the SVSI_SELECTIONMARK in IFolderView::SelectItem. /// The index of the marked item. @@ -281,7 +281,7 @@ namespace Vanara.PInvoke /// Gets the position of an item in the folder's view. /// A pointer to an ITEMIDLIST interface. /// The position of the item's upper-left corner. - Point GetItemPosition([In] PIDL pidl); + Point GetItemPosition([In] IntPtr pidl); /// /// Gets a POINT structure containing the width (x) and height (y) dimensions, including the surrounding white space, of an item. @@ -304,7 +304,7 @@ namespace Vanara.PInvoke /// Selects an item in the folder's view. /// The index of the item to select in the folder's view. /// One of the _SVSIF constants that specify the type of selection to apply. - void SelectItem(int iItem, SVSIF dwFlags); + void SelectItem([In] int iItem, [In] SVSIF dwFlags); /// Allows the selection and positioning of items visible in the folder's view. /// The number of items to select. @@ -314,7 +314,7 @@ namespace Vanara.PInvoke /// name="apidl"/> should be positioned. /// /// One of the _SVSIF constants that specifies the type of selection to apply. - void SelectAndPositionItems(uint cidl, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] PIDL[] apidl, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Point[] apt, SVSIF dwFlags); + void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Point[] apt, [In] SVSIF dwFlags); } /// @@ -332,38 +332,38 @@ namespace Vanara.PInvoke /// Sets the selected folder's view mode. /// One of the following values from the FOLDERVIEWMODE enumeration. - new void SetCurrentViewMode(FOLDERVIEWMODE ViewMode); + new void SetCurrentViewMode([In] FOLDERVIEWMODE ViewMode); /// Gets the folder object. /// Reference to the desired IID to represent the folder. - /// + /// /// When this method returns, contains the interface pointer requested in . This is typically IShellFolder /// or a related interface. This can also be an IShellItemArray with a single element. - /// - [return: MarshalAs(UnmanagedType.IUnknown)] + /// + [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] new object GetFolder(in Guid riid); /// Gets the identifier of a specific item in the folder view, by index. /// The index of the item in the view. - /// The address of a pointer to a PIDL containing the item's identifier information. - new PIDL Item(int iItemIndex); + /// The address of a pointer to a PIDL containing the item's identifier information. + new IntPtr Item([In] int iItemIndex); /// /// Gets the number of items in the folder. This can be the number of all items, or a subset such as the number of selected items. /// /// Flags from the _SVGIO enumeration that limit the count to certain types of items. /// The number of items (files and folders) displayed in the folder view. - new int ItemCount(SVGIO uFlags); + new int ItemCount([In] SVGIO uFlags); /// Gets the address of an enumeration object based on the collection of items in the folder view. /// _SVGIO values that limit the enumeration to certain types of items. /// Reference to the desired IID to represent the folder. - /// + /// /// When this method returns, contains the interface pointer requested in . This is typically an /// IEnumIDList, IDataObject, or IShellItemArray. If an error occurs, this value is NULL. - /// - [return: MarshalAs(UnmanagedType.IUnknown)] - new object Items(SVGIO uFlags, in Guid riid); + /// + [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] + new object Items([In] SVGIO uFlags, in Guid riid); /// Gets the index of an item in the folder's view which has been marked by using the SVSI_SELECTIONMARK in IFolderView::SelectItem. /// The index of the marked item. @@ -376,7 +376,7 @@ namespace Vanara.PInvoke /// Gets the position of an item in the folder's view. /// A pointer to an ITEMIDLIST interface. /// The position of the item's upper-left corner. - new Point GetItemPosition([In] PIDL pidl); + new Point GetItemPosition([In] IntPtr pidl); /// /// Gets a POINT structure containing the width (x) and height (y) dimensions, including the surrounding white space, of an item. @@ -399,7 +399,7 @@ namespace Vanara.PInvoke /// Selects an item in the folder's view. /// The index of the item to select in the folder's view. /// One of the _SVSIF constants that specify the type of selection to apply. - new void SelectItem(int iItem, SVSIF dwFlags); + new void SelectItem([In] int iItem, [In] SVSIF dwFlags); /// Allows the selection and positioning of items visible in the folder's view. /// The number of items to select. @@ -409,7 +409,7 @@ namespace Vanara.PInvoke /// name="apidl"/> should be positioned. /// /// One of the _SVSIF constants that specifies the type of selection to apply. - new void SelectAndPositionItems(uint cidl, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] PIDL[] apidl, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Point[] apt, SVSIF dwFlags); + new void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Point[] apt, [In] SVSIF dwFlags); /// Groups the view by the given property key and direction. /// @@ -462,7 +462,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setviewproperty // DEPRECATED_HRESULT SetViewProperty( PCUITEMID_CHILD pidl, REFPROPERTYKEY propkey, REFPROPVARIANT propvar ); [Obsolete] - void SetViewProperty([In] PIDL pidl, in PROPERTYKEY propkey, [In] PROPVARIANT propvar); + void SetViewProperty([In] IntPtr pidl, in PROPERTYKEY propkey, [In] PROPVARIANT propvar); /// /// @@ -488,7 +488,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getviewproperty // DEPRECATED_HRESULT GetViewProperty( PCUITEMID_CHILD pidl, REFPROPERTYKEY propkey, PROPVARIANT *ppropvar ); [Obsolete] - void GetViewProperty([In] PIDL pidl, in PROPERTYKEY propkey, [In, Out] PROPVARIANT ppropvar); + void GetViewProperty([In] IntPtr pidl, in PROPERTYKEY propkey, [In, Out] PROPVARIANT ppropvar); /// /// @@ -515,7 +515,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-settileviewproperties // DEPRECATED_HRESULT SetTileViewProperties( PCUITEMID_CHILD pidl, LPCWSTR pszPropList ); [Obsolete] - void SetTileViewProperties([In] PIDL pidl, [MarshalAs(UnmanagedType.LPWStr)] string pszPropList); + void SetTileViewProperties([In] IntPtr pidl, [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropList); /// /// @@ -541,7 +541,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setextendedtileviewproperties // DEPRECATED_HRESULT SetExtendedTileViewProperties( PCUITEMID_CHILD pidl, LPCWSTR pszPropList ); [Obsolete] - void SetExtendedTileViewProperties([In] PIDL pidl, [MarshalAs(UnmanagedType.LPWStr)] string pszPropList); + void SetExtendedTileViewProperties([In] IntPtr pidl, [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropList); /// Sets the default text to be used when there are no items in the view. /// @@ -556,7 +556,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-settext HRESULT SetText( // FVTEXTTYPE iType, LPCWSTR pwszText ); - void SetText(FVTEXTTYPE iType, [MarshalAs(UnmanagedType.LPWStr)] string pwszText); + void SetText([In] FVTEXTTYPE iType, [In, MarshalAs(UnmanagedType.LPWStr)] string pwszText); /// Sets and applies specified folder flags. /// @@ -573,7 +573,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setcurrentfolderflags HRESULT // SetCurrentFolderFlags( DWORD dwMask, DWORD dwFlags ); - void SetCurrentFolderFlags(FOLDERFLAGS dwMask, FOLDERFLAGS dwFlags); + void SetCurrentFolderFlags([In] FOLDERFLAGS dwMask, [In] FOLDERFLAGS dwFlags); /// Gets the currently applied folder flags. /// @@ -605,7 +605,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setsortcolumns HRESULT // SetSortColumns( const SORTCOLUMN *rgSortColumns, int cColumns ); - void SetSortColumns([In] SORTCOLUMN[] rgSortColumns, int cColumns); + void SetSortColumns([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SORTCOLUMN[] rgSortColumns, [In] int cColumns); /// Gets the sort columns currently applied to the view. /// @@ -618,7 +618,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getsortcolumns HRESULT // GetSortColumns( SORTCOLUMN *rgSortColumns, int cColumns ); - void GetSortColumns([In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SORTCOLUMN[] rgSortColumns, int cColumns); + void GetSortColumns([In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SORTCOLUMN[] rgSortColumns, [In] int cColumns); /// Retrieves an object that represents a specified item. /// @@ -635,8 +635,8 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getitem HRESULT GetItem( int // iItem, REFIID riid, void **ppv ); - [return: MarshalAs(UnmanagedType.IUnknown)] - object GetItem(int iItem, in Guid riid); + [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] + object GetItem([In] int iItem, in Guid riid); /// Gets the next visible item in relation to a given index in the view. /// @@ -672,7 +672,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getvisibleitem HRESULT // GetVisibleItem( int iStart, BOOL fPrevious, int *piItem ); [PreserveSig] - HRESULT GetVisibleItem(int iStart, [MarshalAs(UnmanagedType.Bool)] bool fPrevious, out int piItem); + HRESULT GetVisibleItem([In] int iStart, [In, MarshalAs(UnmanagedType.Bool)] bool fPrevious, out int piItem); /// Locates the currently selected item at or after a given index. /// The index position from which to start searching for the currently selected item. @@ -696,7 +696,7 @@ namespace Vanara.PInvoke /// /// [PreserveSig] - HRESULT GetSelectedItem(int iStart, out int piItem); + HRESULT GetSelectedItem([In] int iStart, out int piItem); /// /// Gets the current selection as an IShellItemArray. @@ -730,7 +730,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getselection HRESULT // GetSelection( BOOL fNoneImpliesFolder, IShellItemArray **ppsia ); [PreserveSig] - HRESULT GetSelection([MarshalAs(UnmanagedType.Bool)] bool fNoneImpliesFolder, out IShellItemArray ppsia); + HRESULT GetSelection([In, MarshalAs(UnmanagedType.Bool)] bool fNoneImpliesFolder, out IShellItemArray ppsia); /// Gets the selection state including check state. /// @@ -746,7 +746,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getselectionstate HRESULT // GetSelectionState( PCUITEMID_CHILD pidl, DWORD *pdwFlags ); - SVSIF GetSelectionState([In] PIDL pidl); + SVSIF GetSelectionState([In] IntPtr pidl); /// Invokes the given verb on the current selection. /// @@ -756,7 +756,7 @@ namespace Vanara.PInvoke /// If pszVerb is NULL, then the default verb is invoked on the selection. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-invokeverbonselection HRESULT // InvokeVerbOnSelection( LPCSTR pszVerb ); - void InvokeVerbOnSelection([MarshalAs(UnmanagedType.LPWStr)] string pszVerb); + void InvokeVerbOnSelection([In, MarshalAs(UnmanagedType.LPWStr)] string pszVerb); /// Sets and applies the view mode and image size. /// @@ -770,7 +770,7 @@ namespace Vanara.PInvoke /// If iImageSize is -1 then the current default icon size for the view mode is used. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setviewmodeandiconsize // HRESULT SetViewModeAndIconSize( FOLDERVIEWMODE uViewMode, int iImageSize ); - void SetViewModeAndIconSize(FOLDERVIEWMODE uViewMode, int iImageSize); + void SetViewModeAndIconSize([In] FOLDERVIEWMODE uViewMode, [In] int iImageSize = -1); /// Gets the current view mode and icon size applied to the view. /// @@ -793,7 +793,7 @@ namespace Vanara.PInvoke /// If cVisibleRows is zero, subsetting is turned off. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setgroupsubsetcount HRESULT // SetGroupSubsetCount( UINT cVisibleRows ); - void SetGroupSubsetCount(uint cVisibleRows); + void SetGroupSubsetCount([In] uint cVisibleRows); /// Gets the count of visible rows displayed for a group's subset. /// @@ -812,7 +812,7 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setredraw HRESULT SetRedraw( // BOOL fRedrawOn ); - void SetRedraw([MarshalAs(UnmanagedType.Bool)] bool fRedrawOn); + void SetRedraw([In, MarshalAs(UnmanagedType.Bool)] bool fRedrawOn); /// /// Checks to see if this view sourced the current drag-and-drop or cut-and-paste operation (used by drop target objects). diff --git a/PInvoke/Shell32/ShObjIdl.IServiceProvider.cs b/PInvoke/Shell32/ShObjIdl.IServiceProvider.cs index 45994c98..e07e7e94 100644 --- a/PInvoke/Shell32/ShObjIdl.IServiceProvider.cs +++ b/PInvoke/Shell32/ShObjIdl.IServiceProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Vanara.PInvoke @@ -18,7 +19,9 @@ namespace Vanara.PInvoke /// The interface specified by the parameter. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] - HRESULT QueryService(in Guid guidService, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object ppvObject); + //HRESULT QueryService(in Guid guidService, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object ppvObject); + [MethodImpl(MethodImplOptions.InternalCall)] + HRESULT QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject); } } } \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.IShellView.cs b/PInvoke/Shell32/ShObjIdl.IShellView.cs index 2c7f77fb..bfe1082a 100644 --- a/PInvoke/Shell32/ShObjIdl.IShellView.cs +++ b/PInvoke/Shell32/ShObjIdl.IShellView.cs @@ -801,14 +801,14 @@ namespace Vanara.PInvoke /// Enables or disables modeless dialog boxes. This method is not currently implemented. /// true to enable modeless dialog box windows or false to disable them. - void EnableModeless([MarshalAs(UnmanagedType.Bool)] bool enable); + void EnableModeless([In, MarshalAs(UnmanagedType.Bool)] bool enable); /// /// Called when the activation state of the view window is changed by an event that is not caused by the Shell view itself. For /// example, if the TAB key is pressed when the tree has the focus, the view should be given the focus. /// /// Flag specifying the activation state of the window. - void UIActivate(SVUIA uState); + void UIActivate([In] SVUIA uState); /// Refreshes the view's contents in response to user input. void Refresh(); @@ -828,7 +828,7 @@ namespace Vanara.PInvoke /// /// The dimensions of the new view, in client coordinates. /// The address of the window handle being created. - HWND CreateViewWindow(IShellView psvPrevious, in FOLDERSETTINGS pfs, IShellBrowser psb, in RECT prcView); + HWND CreateViewWindow([In] IShellView psvPrevious, in FOLDERSETTINGS pfs, [In] IShellBrowser psb, in RECT prcView); /// Destroys the view window. void DestroyViewWindow(); @@ -841,7 +841,7 @@ namespace Vanara.PInvoke /// Reserved. /// The address of the callback function used to add the pages. /// A value that must be passed as the callback function's lparam parameter. - void AddPropertySheetPages(uint dwReserved, [In] AddPropSheetPageProc lpfn, [In] IntPtr lparam); + void AddPropertySheetPages([In, Optional] uint dwReserved, [In] AddPropSheetPageProc lpfn, [In] IntPtr lparam); /// Saves the Shell's view settings so the current state can be restored during a subsequent browsing session. void SaveViewState(); @@ -849,14 +849,14 @@ namespace Vanara.PInvoke /// Changes the selection state of one or more items within the Shell view window. /// The address of the ITEMIDLIST structure. /// One of the _SVSIF constants that specify the type of selection to apply. - void SelectItem(PIDL pidlItem, SVSIF uFlags); + void SelectItem([In] IntPtr pidlItem, [In] SVSIF uFlags); /// Gets an interface that refers to data presented in the view. /// The constants that refer to an aspect of the view. /// The identifier of the COM interface being requested. /// The address that receives the interface pointer. If an error occurs, the pointer returned must be NULL. - [return: MarshalAs(UnmanagedType.IUnknown)] - object GetItemObject(SVGIO uItem, in Guid riid); + [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] + object GetItemObject([In] SVGIO uItem, in Guid riid); } ///