diff --git a/PInvoke/Shell32/ShObjIdl.IContextMenu.cs b/PInvoke/Shell32/ShObjIdl.IContextMenu.cs index 837dc083..8b7048b2 100644 --- a/PInvoke/Shell32/ShObjIdl.IContextMenu.cs +++ b/PInvoke/Shell32/ShObjIdl.IContextMenu.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; namespace Vanara.PInvoke { @@ -322,6 +323,38 @@ namespace Vanara.PInvoke void HandleMenuMsg2(uint uMsg, IntPtr wParam, IntPtr lParam, IntPtr result); } + /// + /// Exposes a method that enables the callback of a context menu. For example, to add a shield icon to a menuItem that requires elevation. + /// + [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("3409E930-5A39-11d1-83FA-00A0C90DC849")] + public interface IContextMenuCB + { + /// Enables the callback function for a context menu. + /// + /// A pointer to the IShellFolder interface of the object that supports the IContextMenuCB::CallBack interface. The context menu + /// interface is returned on a call to GetUIObjectOf. + /// + /// A handle to the owner of the context menu. This value can be NULL. + /// + /// A pointer to an IDataObject that contains information about a menu selection. Implement interface IDataObject, or call + /// SHCreateDataObject for the default implementation. + /// + /// + /// A notification from the Shell's default menu implementation. For example, the default menu implementation calls + /// DFM_MERGECONTEXTMENU to allow the implementer of IContextMenuCB::CallBack to remove, add, or disable context menu items in + /// this callback. + /// + /// + /// Data specific to the notification specified in uMsg. See the individual notification page for specific requirements. + /// + /// + /// Data specific to the notification specified in uMsg. See the individual notification page for specific requirements. + /// + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PreserveSig] + HRESULT CallBack(IShellFolder psf, IntPtr hwndOwner, IDataObject pdtobj, uint uMsg, IntPtr wParam, IntPtr lParam); + } + /* /// Contains information needed by IContextMenu::InvokeCommand to invoke a shortcut menu command. [StructLayout(LayoutKind.Sequential)] diff --git a/PInvoke/Shell32/ShObjIdl.cs b/PInvoke/Shell32/ShObjIdl.cs index aea237cf..874da062 100644 --- a/PInvoke/Shell32/ShObjIdl.cs +++ b/PInvoke/Shell32/ShObjIdl.cs @@ -27,12 +27,13 @@ namespace Vanara.PInvoke /// Introduced in Windows Vista. Specify this bind context to cause the IShellFolder::BindToObject method to use the object specified by the pbc parameter to create the target object; in this case, the object specified by the punk parameter in the IBindCtx::RegisterObjectParam call must implement the ICreateObject interface. /// Used with IShellFolder::BindToObject or IShellItem::BindToHandler. public const string STR_BIND_DELEGATE_CREATE_OBJECT = "Delegate Object Creation"; - /// Introduced in Windows 7. Passed to IShellFolder::ParseDisplayName along with STR_FILE_SYS_BIND_DATA. This forces simple parsing while also probing for Desktop.ini files along the path from which to get a localized name string. This avoids probing for folders along the path, which, in a case of a folder that represents a server or a share, could take extensive time and resources. Desktop.ini files are cached in some locations, so it will be at least as efficient as probing for folders attributes and then probing for the Desktop.ini if that folder should turn ou tot be read-only. - public const string STR_BIND_FOLDERS_READ_ONLY = "Folders As Read Only"; /// Introduced in Windows 7. Passed to IShellFolder::ParseDisplayName with an FOLDER_ENUM_MODE value to control the enumeration mode of the parsed item. The FOLDER_ENUM_MODE value is passed in the bind context through an object that implements IObjectWithFolderEnumMode. /// Items with different enumeration modes compare canonically(SHCIDS_CANONICALONLY) different because they enumerate different sets of items. /// If an item doesn't support the enumeration mode (because it isn't a folder or it doesn't provide the enumeration mode) then it is created in the default enumeration mode. public const string STR_BIND_FOLDER_ENUM_MODE = "Folder Enum Mode"; + + /// Introduced in Windows 7. Passed to IShellFolder::ParseDisplayName along with STR_FILE_SYS_BIND_DATA. This forces simple parsing while also probing for Desktop.ini files along the path from which to get a localized name string. This avoids probing for folders along the path, which, in a case of a folder that represents a server or a share, could take extensive time and resources. Desktop.ini files are cached in some locations, so it will be at least as efficient as probing for folders attributes and then probing for the Desktop.ini if that folder should turn ou tot be read-only. + public const string STR_BIND_FOLDERS_READ_ONLY = "Folders As Read Only"; /// Introduced in Windows XP SP2. Specify this bind context to force a folder shortcut to resolve the link that points to its target. /// A folder shortcut is a folder item that points to another folder item in the same namespace, using a link(shortcut) to hold the IDList of the target.The link is resolved to track the target in case it is moved or renamed.For example, the Windows XP My Network Places folder and the Windows Vista Computer folder can contain folder shortcuts created with the Add Network Location wizard.To improve performance, the IShellFolder::BindToObject method does not resolve links to network folder by default. /// Used with IShellFolder::BindToObject or IShellItem::BindToHandler. @@ -100,6 +101,12 @@ namespace Vanara.PInvoke public const string STR_PARSE_SKIP_NET_CACHE = "Skip Net Resource Cache"; /// Introduced in Windows XP. Specify this bind context to pass parsed properties to the IShellFolder::ParseDisplayName method for a delegate namespace. The namespace can use the passed properties instead of attempting to parse the name itself. public const string STR_PARSE_TRANSLATE_ALIASES = "Parse Translate Aliases"; + /// Introduced in Windows 7. Specify this property to cause a call to the IShellFolder::ParseDisplayName method to return an IDList bound to the file type association handler for the application. + public const string STR_PARSE_WITH_EXPLICIT_ASSOCAPP = "ExplicitAssociationApp"; + + /// Introduced in Windows 7. Specify this property to cause a call to the IShellFolder::ParseDisplayName method to return an IDList bound to the file association handler of the provided ProgID. + public const string STR_PARSE_WITH_EXPLICIT_PROGID = "ExplicitProgid"; + /// Windows Vista only. A parsing bind context that is used to pass a set of properties and the item's name when calling IShellFolder::ParseDisplayName. The object in the bind context implements IPropertyStore and is retrieved by calling IBindCtx::GetObjectParam. /// DBFolder is a Shell data source that represents items in search results and query-based views.DBFolder retrieves these items by querying the Windows Search system.Items in the search results are identified through a protocol scheme, for example "file:" or "mapi:". DBFolder provides the behavior for these items by delegating to Shell data sources that are created for these protocols. See Developing Protocol Handler Add-ins for more information. /// When DBFolder delegates its parsing operation to the Shell data sources that support Windows Search protocols, this bind context provides access to values that were returned in the query result for that item. This includes the following: @@ -112,22 +119,18 @@ namespace Vanara.PInvoke /// This bind context can also be used to parse a DBFolder item if a client has a set of properties that define the item.In this case an empty name should be passed to IShellFolder::ParseDisplayName. /// Before Windows 7, this value was not defined in a header file.It could be defined by the caller or passed as its string value: L"ParseWithProperties". As of Windows 7, the value is defined in Shlobj.h.Note that this is a different header than where the other STR constants are defined. public const string STR_PARSE_WITH_PROPERTIES = "ParseWithProperties"; - /// Introduced in Windows 7. Specify this property to cause a call to the IShellFolder::ParseDisplayName method to return an IDList bound to the file type association handler for the application. - public const string STR_PARSE_WITH_EXPLICIT_ASSOCAPP = "ExplicitAssociationApp"; - /// Introduced in Windows 7. Specify this property to cause a call to the IShellFolder::ParseDisplayName method to return an IDList bound to the file association handler of the provided ProgID. - public const string STR_PARSE_WITH_EXPLICIT_PROGID = "ExplicitProgid"; /// Introduced in Windows 8. Specify this bind context to indicate that the bind context parameter is a property bag (IPropertyBag) used to pass VARIANT values in the bind context. See the Remarks section for further details. public const string STR_PROPERTYBAG_PARAM = "SHBindCtxPropertyBag"; - /// Introduced in Windows XP. Specify this bind context to cause calls to the IShellFolder::ParseDisplayName or IShellFolder::BindToObject methods to ignore a particular Shell namespace extension when parsing or binding. The CLSID of the namespace to ignore is provided by the IPersist::GetClassID method of the bind parameter. - public const string STR_SKIP_BINDING_CLSID = "Skip Binding CLSID"; - /// Not used. - public const string STR_TRACK_CLSID = "Track the CLSID"; - /// The string referrer identifier public const string STR_REFERRER_IDENTIFIER = "Referrer Identifier"; + + /// Introduced in Windows XP. Specify this bind context to cause calls to the IShellFolder::ParseDisplayName or IShellFolder::BindToObject methods to ignore a particular Shell namespace extension when parsing or binding. The CLSID of the namespace to ignore is provided by the IPersist::GetClassID method of the bind parameter. + public const string STR_SKIP_BINDING_CLSID = "Skip Binding CLSID"; /// The string tab reuse identifier public const string STR_TAB_REUSE_IDENTIFIER = "Tab Reuse Identifier"; + /// Not used. + public const string STR_TRACK_CLSID = "Track the CLSID"; /// Values that specify from which category the list of destinations should be retrieved. [PInvokeData("Shobjidl.h", MSDNShortId = "dd378410")] public enum APPDOCLISTTYPE @@ -139,6 +142,53 @@ namespace Vanara.PInvoke FREQUENT } + /// Specifies the enumeration handler filter applied to the full list of handlers in SHAssocEnumHandlers. + [PInvokeData("shobjidl_core.h", MSDNShortId = "83db466b-e00c-4015-879f-c5c222f45b8c")] + public enum ASSOC_FILTER + { + /// Return all handlers. + ASSOC_FILTER_NONE = 0x0, + /// + /// Return only recommended handlers. A handler sets its recommended status in the registry when it is installed. An initial + /// status of non-recommended can later be promoted to recommended as a result of user action. + /// + ASSOC_FILTER_RECOMMENDED = 0x1, + } + + /// Specifies the source of the default association for a file name extension. Used by methods of the IApplicationAssociationRegistration interface. + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-associationlevel + // typedef enum ASSOCIATIONLEVEL { AL_MACHINE , AL_EFFECTIVE , AL_USER } ; + [PInvokeData("shobjidl_core.h", MSDNShortId = "846ce9f4-092a-420d-be73-0951efc4368f")] + public enum ASSOCIATIONLEVEL + { + /// The machine-level default application association. + AL_MACHINE, + /// The effective default for the current user. This value should be used by most applications. + AL_EFFECTIVE, + /// The per-user default application association. If this value is used and no per-user default is declared, the calling method fails with a value of . + AL_USER, + } + + /// + /// Specifies the type of association for an application. Used by methods of the IApplicationAssociationRegistration interface. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-associationtype + [PInvokeData("shobjidl_core.h")] + public enum ASSOCIATIONTYPE + { + /// Indicates a file name extension, such as .htm or .mp3. + AT_FILEEXTENSION, + /// Indicates a protocol, such as http or mailto. + AT_URLPROTOCOL, + /// + /// Indicates the owner of the startmenu client for a mail or Internet hyperlink. As of Windows 7, this value is used only for + /// the MAPI sendmail client. + /// + AT_STARTMENUCLIENT, + /// Indicates the MIME type, such as audio/mp3. + AT_MIMETYPE, + } + /// One of the following values that indicate which known category to add to the list [PInvokeData("Shobjidl.h", MSDNShortId = "dd378397")] public enum KNOWNDESTCATEGORY @@ -191,6 +241,33 @@ namespace Vanara.PInvoke SVGIO_FLAG_VIEWORDER = 0x80000000, } + /// + /// + /// Exposes methods that query and set default applications for specific file Association Type, and protocols at a specific + /// Association Level. + /// + /// Note As of Windows 8, the only functionality of this interface that is supported is QueryCurrentDefault. + /// + /// + /// + /// Because IApplicationAssociationRegistration is only supported for Windows Vista and Windows 7, applications that support + /// earlier operating systems must use their preexisting code in relation to defaults when running under those operating systems. + /// Those applications should include a check for the operating system version to account for this. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-iapplicationassociationregistration + [PInvokeData("shobjidl_core.h", MSDNShortId = "015a3be4-2e74-4a2b-8c02-54dcbf0ecacd")] + [ComImport, Guid("4e530b0a-e611-4c77-a3ac-9031d022281b"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(ApplicationAssociationRegistration))] + public interface IApplicationAssociationRegistration + { + void QueryCurrentDefault([MarshalAs(UnmanagedType.LPWStr)] string pszQuery, ASSOCIATIONTYPE atQueryType, ASSOCIATIONLEVEL alQueryLevel, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CoTaskMemStringMarshaler))] out string ppszAssociation); + void QueryAppIsDefault([MarshalAs(UnmanagedType.LPWStr)] string pszQuery, ASSOCIATIONTYPE atQueryType, ASSOCIATIONLEVEL alQueryLevel, [MarshalAs(UnmanagedType.LPWStr)] string pszAppRegistryName, [MarshalAs(UnmanagedType.Bool)] out bool pfDefault); + void QueryAppIsDefaultAll(ASSOCIATIONLEVEL alQueryLevel, [MarshalAs(UnmanagedType.LPWStr)] string pszAppRegistryName, [MarshalAs(UnmanagedType.Bool)] out bool pfDefault); + void SetAppAsDefault([MarshalAs(UnmanagedType.LPWStr)] string pszAppRegistryName, [MarshalAs(UnmanagedType.LPWStr)] string pszSet, ASSOCIATIONTYPE atSetType); + void SetAppAsDefaultAll([MarshalAs(UnmanagedType.LPWStr)] string pszAppRegistryName); + void ClearUserAssociations(); + } + /// Exposes methods that allow an application to remove one or all destinations from the Recent or Frequent categories in a Jump List. [SuppressUnmanagedCodeSecurity] [ComImport, Guid("12337d35-94c6-48a0-bce7-6a9c69d4d600"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] @@ -235,6 +312,68 @@ namespace Vanara.PInvoke object GetList(APPDOCLISTTYPE listtype, uint cItemsDesired, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid); } + /// Exposes methods to set default icons associated with an object. + [ComImport, Guid("41ded17d-d6b3-4261-997d-88c60e4b1d58"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [PInvokeData("Shobjidl.h")] + public interface IDefaultExtractIconInit + { + /// Sets GIL_XXX flags. See GetIconLocation + /// Specifies return flags to get icon location. + void SetFlags(GetIconLocationFlags uFlags); + + /// Sets the registry key from which to load the "DefaultIcon" value. + /// A handle to the registry key. + void SetKey(IntPtr hkey); + + /// Sets the normal icon. + /// + /// A pointer to a buffer that contains the full icon path, including the file name and extension, as a Unicode string. This + /// pointer can be NULL. + /// + /// A Shell icon ID. + void SetNormalIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon); + + /// Sets the icon that allows containers to specify an "open" look. + /// + /// A pointer to a buffer that contains the full icon path, including the file name and extension, as a Unicode string. This + /// pointer can be NULL. + /// + /// Shell icon ID. + void SetOpenIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon); + + /// Sets the icon for a shortcut to the object. + /// + /// A pointer to a buffer that contains the full icon path, including the file name and extension, as a Unicode string. This + /// pointer can be NULL. + /// + /// Shell icon ID. + void SetShortcutIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon); + + /// Sets the default icon. + /// + /// A pointer to a buffer that contains the full icon path, including the file name and extension, as a Unicode string. This + /// pointer can be NULL. + /// + /// The Shell icon ID. + void SetDefaultIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon); + } + + /// Exposes a method that allows enumeration of a collection of handlers associated with particular file name extensions. + [ComImport, Guid("973810ae-9599-4b88-9e4d-6ee98c9552da"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [PInvokeData("shobjidl_core.h", MSDNShortId = "9e173cb3-bd73-437c-8853-c13c8b6f216f")] + public interface IEnumAssocHandlers + { + /// Retrieves a specified number of elements. + /// The number of elements to retrieve. + /// + /// When this method returns, contains the address of an array of IAssocHandler pointers. Each IAssocHandler represents a single handler. + /// + /// When this method returns, contains a pointer to the number of elements retrieved. + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PreserveSig] + HRESULT Next(uint celt, out IntPtr rgelt, out uint pceltFetched); + } + /// /// Exposes a standard set of methods used to enumerate the pointers to item identifier lists (PIDLs) of the items in a Shell folder. When a folder's /// IShellFolder::EnumObjects method is called, it creates an enumeration object and passes a pointer to the object's IEnumIDList interface back to the @@ -622,6 +761,148 @@ namespace Vanara.PInvoke [PInvokeData("Shobjidl.h", MSDNShortId = "dd378422")] public static extern HRESULT SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); + /// + /// Returns an enumeration object for a specified set of file name extension handlers. + /// + /// + /// Type: PCWSTR + /// + /// A pointer to a null-terminated buffer that contains a single file type extension, for instance ".jpg". Only handlers associated + /// with the given extension are enumerated. If this value is NULL, all handlers for all extensions are enumerated. + /// + /// + /// + /// Type: ASSOC_FILTER + /// + /// Specifies the enumeration handler filter applied to the full list of handlers that results from the value given in . One of the + /// following values. + /// + /// ASSOC_FILTER_NONE + /// Return all handlers. + /// ASSOC_FILTER_RECOMMENDED + /// + /// Return only recommended handlers. A handler sets its recommended status in the registry when it is installed. An initial status + /// of non-recommended can later be promoted to recommended as a result of user action. + /// + /// + /// + /// Type: IEnumAssocHandlers** + /// When this method returns, contains the address of a pointer to an IEnumAssocHandlers object. + /// + /// + /// Type: HRESULT + /// If this function 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-shassocenumhandlers + // SHSTDAPI SHAssocEnumHandlers( PCWSTR pszExtra, ASSOC_FILTER afFilter, IEnumAssocHandlers **ppEnumHandler ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shobjidl_core.h", MSDNShortId = "83db466b-e00c-4015-879f-c5c222f45b8c")] + public static extern HRESULT SHAssocEnumHandlers([MarshalAs(UnmanagedType.LPWStr)] string pszExtra, ASSOC_FILTER afFilter, out IEnumAssocHandlers ppEnumHandler); + /// + /// Gets an enumeration interface that provides access to handlers associated with a given protocol. + /// + /// + /// Type: PCWSTR + /// Pointer to a string that specifies the protocol. + /// + /// + /// Type: REFIID + /// A reference to the IID of the interface to retrieve through , typically IID_IEnumAssocHandlers. + /// + /// + /// Type: void** + /// When this method returns, contains the interface pointer requested in . This is typically IEnumAssocHandlers. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// It is recommended that you use the IID_PPV_ARGS macro, defined in Objbase.h, to package the and parameters. This macro + /// provides the correct IID based on the interface pointed to by the value in , which eliminates the possibility of a coding error. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shassocenumhandlersforprotocolbyapplication + // SHSTDAPI SHAssocEnumHandlersForProtocolByApplication( PCWSTR protocol, REFIID riid, void **enumHandlers ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shobjidl_core.h", MSDNShortId = "8bc3b9ce-5909-46a0-b5f1-35ab808aaa55")] + public static extern HRESULT SHAssocEnumHandlersForProtocolByApplication([MarshalAs(UnmanagedType.LPWStr)] string protocol, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object enumHandlers); + + /// + /// Creates an IApplicationAssociationRegistration object based on the stock implementation of the interface provided by Windows. + /// + /// + /// Type: REFIID + /// A reference to the IID of the requested interface. + /// + /// + /// Type: void** + /// When this function returns, contains the address of a pointer to the IApplicationAssociationRegistration object. + /// + /// + /// Type: HRESULT + /// If this function 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-shcreateassociationregistration + // SHSTDAPI SHCreateAssociationRegistration( REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shobjidl_core.h", MSDNShortId = "7998f49d-2515-4c77-991e-62c0fefa43df")] + public static extern HRESULT SHCreateAssociationRegistration([In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IApplicationAssociationRegistration ppv); + /// + /// Creates a standard icon extractor, whose defaults can be further configured via the IDefaultExtractIconInit interface. + /// + /// + /// Type: REFIID + /// A reference to interface ID. + /// + /// + /// Type: void** + /// The address of IDefaultExtractIconInit interface pointer. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// The intended usage for this function is as follows: + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shcreatedefaultextracticon + // HRESULT SHCreateDefaultExtractIcon( REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shobjidl_core.h", MSDNShortId = "483dc9ae-4820-47f1-888e-ad7a6bdf3d29")] + public static extern HRESULT SHCreateDefaultExtractIcon([In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IDefaultExtractIconInit ppv); + + /// + /// Creates a file operation that sets the default properties on the Shell item that have not already been set. + /// + /// + /// Type: IShellItem* + /// A pointer to the source shell item. See IShellItem. + /// + /// + /// Type: IFileOperation** + /// The address of the IFileOperation interface pointer. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// The list of properties to set a default value comes from the SetDefaultsFor registry entry under the ProgID for the file + /// association of the item. The list is prefixed by and contains the canonical names of the properties to set the default value, for + /// example, . The possible properties for this list are System.Author, System.Document.DateCreated, and System.Photo.DateTaken. If + /// the SetDefaultsFor entry does not exist on the ProgID, this function uses the default found on the SetDefaultsFor + /// entry of HKEY_CLASSES_ROOT<b>*. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-shcreatedefaultpropertiesop + // SHSTDAPI SHCreateDefaultPropertiesOp( IShellItem *psi, IFileOperation **ppFileOp ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shobjidl.h", MSDNShortId = "5202ac48-16e7-4d64-8a69-2493036e1e11")] + public static extern HRESULT SHCreateDefaultPropertiesOp(IShellItem psi, out IFileOperation ppFileOp); + /// /// Creates and initializes a Shell item object from a pointer to an item identifier list (PIDL). The resulting shell item object supports the IShellItem interface. /// @@ -689,11 +970,6 @@ namespace Vanara.PInvoke public static extern HRESULT SHCreateItemWithParent([In] PIDL pidlParent, [In, MarshalAs(UnmanagedType.Interface)] IShellFolder psfParent, [In] PIDL pidl, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvItem); - // [DllImport(Lib.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true)] - // [SecurityCritical, SuppressUnmanagedCodeSecurity] - // [PInvokeData("Shlobj.h", MSDNShortId = "bb762141")] - // public static extern HRESULT SHCreateShellFolderView([In] ref SFV_CREATE pcsfv, [MarshalAs(UnmanagedType.Interface)] out object ppvItem); - /// /// Creates a Shell item array object. /// @@ -706,8 +982,12 @@ namespace Vanara.PInvoke [SecurityCritical, SuppressUnmanagedCodeSecurity] [PInvokeData("Shobjidl.h", MSDNShortId = "bb762144")] public static extern HRESULT SHCreateShellItemArray([In] PIDL pidlParent, [In, MarshalAs(UnmanagedType.Interface)] IShellFolder psf, - uint cidl, [In] PIDL ppidl, out IShellItemArray ppsiItemArray); + uint cidl, [In] PIDL ppidl, out IShellItemArray ppsiItemArray); + // [DllImport(Lib.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true)] + // [SecurityCritical, SuppressUnmanagedCodeSecurity] + // [PInvokeData("Shlobj.h", MSDNShortId = "bb762141")] + // public static extern HRESULT SHCreateShellFolderView([In] ref SFV_CREATE pcsfv, [MarshalAs(UnmanagedType.Interface)] out object ppvItem); /// /// Creates a Shell item array object from a list of ITEMIDLIST structures. /// @@ -766,6 +1046,10 @@ namespace Vanara.PInvoke [PInvokeData("Shobjidl.h", MSDNShortId = "bb776437")] internal static extern IntPtr IntILCombine(IntPtr pidl1, IntPtr pidl2); + /// Implements CLSID_ApplicationAssociationRegistration to create IApplicationAssociationRegistration. + [PInvokeData("shobjidl_core.h")] + [ComImport, Guid("591209c7-767b-42b2-9fba-44ee4615f2c7"), ClassInterface(ClassInterfaceType.None)] + public class ApplicationAssociationRegistration { } /// Class interface for IEnumerableObjectCollection. [ComImport, Guid("2d3468c1-36a7-43b6-ac24-d3f02fd9607a"), ClassInterface(ClassInterfaceType.None)] public class CEnumerableObjectCollection { } diff --git a/PInvoke/Shell32/ShellApi.cs b/PInvoke/Shell32/ShellApi.cs index 11643230..0ff5f2cf 100644 --- a/PInvoke/Shell32/ShellApi.cs +++ b/PInvoke/Shell32/ShellApi.cs @@ -1,12 +1,121 @@ using System; using System.IO; using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using System.Text; +using Vanara.InteropServices; +using static Vanara.PInvoke.Kernel32; +using static Vanara.PInvoke.Ole32; +using static Vanara.PInvoke.PropSys; +using static Vanara.PInvoke.ShlwApi; namespace Vanara.PInvoke { /// Interfaces, functions, enumerated types and structures for Shell32.dll. public static partial class Shell32 { + /// Values used in APPBARDATA. + [PInvokeData("shellapi.h", MSDNShortId = "cf86fe15-4beb-49b7-b73e-2ad61cedc3f8")] + public enum ABE + { + /// Left edge. + ABE_LEFT = 0, + /// Top edge. + ABE_TOP = 1, + /// Right edge. + ABE_RIGHT = 2, + /// Bottom edge. + ABE_BOTTOM = 3, + } + + /// Values used by SHAppBarMessage. + [PInvokeData("shellapi.h", MSDNShortId = "173d6eff-b33b-4d7d-bedd-5ebfb1e45954")] + public enum ABM + { + /// Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. + ABM_NEW = 0x00000000, + + /// Unregisters an appbar, removing the bar from the system's internal list. + ABM_REMOVE = 0x00000001, + + /// Requests a size and screen position for an appbar. + ABM_QUERYPOS = 0x00000002, + + /// Sets the size and screen position of an appbar. + ABM_SETPOS = 0x00000003, + + /// Retrieves the autohide and always-on-top states of the Windows taskbar. + ABM_GETSTATE = 0x00000004, + + /// Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app bars—the working area available to your application—, use the GetMonitorInfo function. + ABM_GETTASKBARPOS = 0x00000005, + + /// Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate. + ABM_ACTIVATE = 0x00000006, + + /// Retrieves the handle to the autohide appbar associated with a particular edge of the screen. + ABM_GETAUTOHIDEBAR = 0x00000007, + + /// Registers or unregisters an autohide appbar for an edge of the screen. + ABM_SETAUTOHIDEBAR = 0x00000008, + + /// Notifies the system when an appbar's position has changed. + ABM_WINDOWPOSCHANGED = 0x00000009, + + /// Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes. + ABM_SETSTATE = 0x0000000A, + + /// Windows XP and later: Retrieves the handle to the autohide appbar associated with a particular edge of a particular monitor. + ABM_GETAUTOHIDEBAREX = 0x0000000B, + + /// Windows XP and later: Registers or unregisters an autohide appbar for an edge of a particular monitor. + ABM_SETAUTOHIDEBAREX = 0x0000000C, + } + + /// Where to obtain association data and the form the data is stored in. + [PInvokeData("shellapi.h", MSDNShortId = "1d1a963f-7ebb-4ba6-9a97-795c8ef11ae4")] + public enum ASSOCCLASS + { + /// The hkClass member names a key found as HKEY_CLASSES_ROOT\ SystemFileAssociations\ hkClass. + ASSOCCLASS_SHELL_KEY = 0, + /// The hkClass member provides the full registry path of a ProgID. + ASSOCCLASS_PROGID_KEY, + /// The pszClass member names a ProgID found as HKEY_CLASSES_ROOT\ pszClass. + ASSOCCLASS_PROGID_STR, + /// The hkClass member provides the full registry path of a CLSID. + ASSOCCLASS_CLSID_KEY, + /// The hkClass member names a CLSID found as HKEY_CLASSES_ROOT\ CLSID\ pszClass. + ASSOCCLASS_CLSID_STR, + /// The hkClass member provides the full registry path of an application identifier (APPID). + ASSOCCLASS_APP_KEY, + /// + /// The APPID storing the application information is found at HKEY_CLASSES_ROOT\ Applications\ FileName + /// where FileName is obtained by sending pszClass to PathFindFileName. + /// + ASSOCCLASS_APP_STR, + /// The pszClass member names a key found as HKEY_CLASSES_ROOT\ SystemFileAssociations\ pszClass. + ASSOCCLASS_SYSTEM_STR, + /// + /// Use the association information for folders stored under HKEY_CLASSES_ROOT\ Folder. When this flag is set, + /// hkClass and pszClass are ignored. + /// + ASSOCCLASS_FOLDER, + /// + /// Use the association information stored under the HKEY_CLASSES_ROOT\ * subkey. When this flag is set, + /// hkClass and pszClass are ignored. + /// + ASSOCCLASS_STAR, + /// + /// Introduced in Windows 8. Do not use the user defaults to apply the mapping of the class specified by the pszClass member. + /// + ASSOCCLASS_FIXED_PROGID_STR, + /// + /// Introduced in Windows 8. Use the user defaults to apply the mapping of the class specified by the pszClass member; the class + /// is a protocol. + /// + ASSOCCLASS_PROTOCOL_STR, + } + /// Flags that indicate the content and validity of the other structure members in . [PInvokeData("Shellapi.h", MSDNShortId = "bb759784")] [Flags] @@ -242,6 +351,332 @@ namespace Vanara.PInvoke /// SHGFI_OVERLAYINDEX = 0x000000040 } + /// + /// Retrieves an object that implements an IQueryAssociations interface. + /// + /// + /// Type: const ASSOCIATIONELEMENT* + /// A pointer to an array of ASSOCIATIONELEMENT structures. + /// + /// + /// Type: ULONG + /// The number of elements in the array pointed to by . + /// + /// + /// Type: REFIID + /// Reference to the desired IID, normally IID_IQueryAssociations. + /// + /// + /// Type: void** + /// When this method returns, contains the interface pointer requested in . This is normally IQueryAssociations. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// For systems earlier than Windows Vista, use the AssocCreate function. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-assoccreateforclasses + // SHSTDAPI AssocCreateForClasses( const ASSOCIATIONELEMENT *rgClasses, ULONG cClasses, REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shellapi.h", MSDNShortId = "43257507-dd5e-4622-8445-c132187fd1e5")] + public static extern HRESULT AssocCreateForClasses([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ASSOCIATIONELEMENT[] rgClasses, uint cClasses, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv); + + /// + /// + /// Parses a Unicode command line string and returns an array of pointers to the command line arguments, along with a count of such + /// arguments, in a way that is similar to the standard C run-time and values. + /// + /// + /// + /// Type: LPCWSTR + /// + /// Pointer to a null-terminated Unicode string that contains the full command line. If this parameter is an empty string the + /// function returns the path to the current executable file. + /// + /// + /// + /// Type: int* + /// Pointer to an int that receives the number of array elements returned, similar to . + /// + /// + /// Type: LPWSTR* + /// A pointer to an array of LPWSTR values, similar to . + /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. + /// + /// + /// + /// The address returned by CommandLineToArgvW is the address of the first element in an array of LPWSTR values; the + /// number of pointers in this array is indicated by . Each pointer to a null-terminated Unicode string represents an + /// individual argument found on the command line. + /// + /// + /// CommandLineToArgvW allocates a block of contiguous memory for pointers to the argument strings, and for the argument + /// strings themselves; the calling application must free the memory used by the argument list when it is no longer needed. To free + /// the memory, use a single call to the LocalFree function. + /// + /// For more information about the and argument convention, see Argument Definitions and Parsing C++ Command-Line Arguments. + /// The GetCommandLineW function can be used to get a command line string that is suitable for use as the parameter. + /// + /// This function accepts command lines that contain a program name; the program name can be enclosed in quotation marks or not. + /// + /// + /// CommandLineToArgvW has a special interpretation of backslash characters when they are followed by a quotation mark + /// character ("). This interpretation assumes that any preceding argument is a valid file system path, or else it may behave unpredictably. + /// + /// + /// This special interpretation controls the "in quotes" mode tracked by the parser. When this mode is off, whitespace terminates the + /// current argument. When on, whitespace is added to the argument like all other characters. + /// + /// + /// + /// 2 backslashes followed by a quotation mark produce backslashes followed by begin/end quote. This does not become part of the + /// parsed argument, but toggles the "in quotes" mode. + /// + /// + /// (2) + 1 backslashes followed by a quotation mark again produce backslashes followed by a quotation mark literal ("). This does + /// not toggle the "in quotes" mode. + /// + /// backslashes not followed by a quotation mark simply produce backslashes. + /// + /// + /// ImportantCommandLineToArgvW treats whitespace outside of quotation marks as argument delimiters. However, if starts + /// with any amount of whitespace, CommandLineToArgvW will consider the first argument to be an empty string. Excess + /// whitespace at the end of is ignored. + /// + /// Examples + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw + // LPWSTR * CommandLineToArgvW( LPCWSTR lpCmdLine, int *pNumArgs ); + [DllImport(Lib.Shell32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] + [PInvokeData("shellapi.h", MSDNShortId = "9889a016-b7a5-402b-8305-6f7c199d41b3")] + [return: MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] + public static extern string[] CommandLineToArgvW(string lpCmdLine, out int pNumArgs); + + /// + /// Registers whether a window accepts dropped files. + /// + /// + /// Type: HWND + /// The identifier of the window that is registering whether it will accept dropped files. + /// + /// + /// Type: BOOL + /// + /// A value that indicates if the window identified by the parameter accepts dropped files. This value is TRUE to accept + /// dropped files or FALSE to discontinue accepting dropped files. + /// + /// + /// + /// No return value. + /// + /// + /// + /// An application that calls DragAcceptFiles with the parameter set to TRUE has identified itself as able to process + /// the WM_DROPFILES message from File Manager. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-dragacceptfiles + // void DragAcceptFiles( HWND hWnd, BOOL fAccept ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shellapi.h", MSDNShortId = "1f16f6e4-7847-4bc7-adce-995876db24bd")] + public static extern void DragAcceptFiles(HandleRef hWnd, [MarshalAs(UnmanagedType.Bool)] bool fAccept); + + /// + /// Releases memory that the system allocated for use in transferring file names to the application. + /// + /// + /// Type: HDROP + /// + /// Identifier of the structure that describes dropped files. This handle is retrieved from the parameter of the WM_DROPFILES message. + /// + /// + /// + /// No return value. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-dragfinish + // void DragFinish( HDROP hDrop ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shellapi.h", MSDNShortId = "9b15e8a5-de68-4dcb-8e1a-0ee0393aa9db")] + public static extern void DragFinish(IntPtr hDrop); + + /// + /// Retrieves the names of dropped files that result from a successful drag-and-drop operation. + /// + /// + /// Type: HDROP + /// Identifier of the structure that contains the file names of the dropped files. + /// + /// + /// Type: UINT + /// + /// Index of the file to query. If the value of this parameter is 0xFFFFFFFF, DragQueryFile returns a count of the files + /// dropped. If the value of this parameter is between zero and the total number of files dropped, DragQueryFile copies the + /// file name with the corresponding value to the buffer pointed to by the parameter. + /// + /// + /// + /// Type: LPTSTR + /// + /// The address of a buffer that receives the file name of a dropped file when the function returns. This file name is a + /// null-terminated string. If this parameter is NULL, DragQueryFile returns the required size, in characters, of this buffer. + /// + /// + /// + /// Type: UINT + /// The size, in characters, of the buffer. + /// + /// + /// Type: UINT + /// A nonzero value indicates a successful call. + /// + /// When the function copies a file name to the buffer, the return value is a count of the characters copied, not including the + /// terminating null character. + /// + /// + /// If the index value is 0xFFFFFFFF, the return value is a count of the dropped files. Note that the index variable itself returns + /// unchanged, and therefore remains 0xFFFFFFFF. + /// + /// + /// If the index value is between zero and the total number of dropped files, and the buffer address is NULL, the return value + /// is the required size, in characters, of the buffer, the terminating null character. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-dragqueryfilea + // UINT DragQueryFileA( HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shellapi.h", MSDNShortId = "93fab381-9035-46c4-ba9d-efb2d0801d84")] + public static extern uint DragQueryFile(IntPtr hDrop, uint iFile, string lpszFile, uint cch); + + /// + /// Retrieves the position of the mouse pointer at the time a file was dropped during a drag-and-drop operation. + /// + /// + /// Type: HDROP + /// Handle of the drop structure that describes the dropped file. + /// + /// + /// TBD + /// + /// + /// Type: BOOL + /// TRUE if the drop occurred in the client area of the window; otherwise FALSE. + /// + /// + /// The window for which coordinates are returned is the window that received the WM_DROPFILES message. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-dragquerypoint + // BOOL DragQueryPoint( HDROP hDrop, POINT *ppt ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shellapi.h", MSDNShortId = "87794ab0-a075-4a1f-869f-5998bdc57a1d")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DragQueryPoint(IntPtr hDrop, ref System.Drawing.Point ppt); + + /// Creates a duplicate of a specified icon. + /// Type: HINSTANCE + /// + /// Type: HICON + /// Handle to the icon to be duplicated. + /// + /// + /// Type: HICON + /// If successful, the function returns the handle to the new icon that was created; otherwise, NULL. + /// + // HICON DuplicateIcon( _Reserved_ HINSTANCE hInst, _In_ HICON hIcon); + // https://msdn.microsoft.com/en-us/library/windows/desktop/bb776411(v=vs.85).aspx + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("Shellapi.h", MSDNShortId = "bb776411")] + public static extern IntPtr DuplicateIcon(SafeLibraryHandle hInst, IntPtr hIcon); + + /// + /// Gets a handle to an icon stored as a resource in a file or an icon stored in a file's associated executable file. + /// + /// A handle to the instance of the calling application. + /// Pointer to a string that, on entry, specifies the full path and file name of the file that contains the icon. The function extracts the icon handle from that file, or from an executable file associated with that file. + /// When this function returns, if the icon handle was obtained from an executable file (either an executable file pointed to by lpIconPath or an associated executable file) the function stores the full path and file name of that executable in the buffer pointed to by this parameter. + /// Pointer to a WORD value that, on entry, specifies the index of the icon whose handle is to be obtained. + /// When the function returns, if the icon handle was obtained from an executable file(either an executable file pointed to by lpIconPath or an associated executable file), this value points to the icon's index in that file. + /// If the function succeeds, the return value is an icon handle. If the icon is extracted from an associated executable file, the function stores the full path and file name of the executable file in the string pointed to by lpIconPath, and stores the icon's identifier in the WORD pointed to by lpiIcon. + /// If the function fails, the return value is NULL. + // public static Icon ExtractAssociatedIcon( string filePath ) + // https://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon(v=vs.110).aspx + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("Shellapi.h", MSDNShortId = "bb776414")] + public static extern IntPtr ExtractAssociatedIcon(SafeLibraryHandle hInst, StringBuilder lpIconPath, ref ushort lpiIcon); + + /// + /// + /// Gets a handle to an icon stored as a resource in a file or an icon stored in a file's associated executable file. It extends the + /// ExtractAssociatedIcon function by retrieving the icon's ID when that icon is extracted from an executable file. + /// + /// + /// + /// Type: HINSTANCE + /// The handle of the module from which to extract the icon. + /// + /// + /// TBD + /// + /// + /// TBD + /// + /// + /// TBD + /// + /// + /// Type: HICON + /// Returns the icon's handle if successful, otherwise NULL. + /// + /// + /// The icon handle returned by this function must be released by calling DestroyIcon when it is no longer needed. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-extractassociatediconexa + // HICON ExtractAssociatedIconExA( HINSTANCE hInst, LPSTR pszIconPath, WORD *piIconIndex, WORD *piIconId ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shellapi.h", MSDNShortId = "f32260b0-917b-4406-aeee-34f71a7c7309")] + public static extern IntPtr ExtractAssociatedIconEx(SafeLibraryHandle hInst, StringBuilder pszIconPath, ref ushort piIconIndex, ref ushort piIconId); + + /// + /// Gets a handle to an icon from the specified executable file, DLL, or icon file. + /// To retrieve an array of handles to large or small icons, use the ExtractIconEx function. + /// + /// + /// Type: HINSTANCE + /// Handle to the instance of the application that calls the function. + /// + /// + /// Type: LPCTSTR + /// Pointer to a null-terminated string that specifies the name of an executable file, DLL, or icon file. + /// + /// + /// Type: UINT + /// + /// Specifies the zero-based index of the icon to retrieve. For example, if this value is 0, the function returns a handle to the + /// first icon in the specified file. + /// + /// + /// If this value is -1, the function returns the total number of icons in the specified file. If the file is an executable file or + /// DLL, the return value is the number of RT_GROUP_ICON resources. If the file is an .ICO file, the return value is 1. + /// + /// + /// If this value is a negative number not equal to –1, the function returns a handle to the icon in the specified file whose + /// resource identifier is equal to the absolute value of nIconIndex. For example, you should use –3 to extract the icon whose + /// resource identifier is 3. To extract the icon whose resource identifier is 1, use the ExtractIconEx function. + /// + /// + /// + /// Type: HICON + /// + /// The return value is a handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If + /// no icons were found in the file, the return value is NULL. + /// + /// + // HICON ExtractIcon( _Reserved_ HINSTANCE hInst, _In_ LPCTSTR lpszExeFileName, UINT nIconIndex); + // https://msdn.microsoft.com/en-us/library/windows/desktop/bb776416(v=vs.85).aspx + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("Shellapi.h", MSDNShortId = "bb776416")] + public static extern IntPtr ExtractIcon(SafeLibraryHandle hInst, string lpszExeFileName, uint nIconIndex); /// /// The ExtractIconEx function creates an array of handles to large or small icons extracted from the specified executable file, DLL, or icon file. @@ -260,6 +695,270 @@ namespace Vanara.PInvoke [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] IntPtr[] phIconLarge, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] IntPtr[] phIconSmall, int nIcons); + /// + /// Retrieves the name of and handle to the executable (.exe) file associated with a specific document file. + /// + /// + /// Type: LPCTSTR + /// The address of a null-terminated string that specifies a file name. This file should be a document. + /// + /// + /// Type: LPCTSTR + /// The address of a null-terminated string that specifies the default directory. This value can be NULL. + /// + /// + /// Type: LPTSTR + /// + /// The address of a buffer that receives the file name of the associated executable file. This file name is a null-terminated + /// string that specifies the executable file started when an "open" by association is run on the file specified in the parameter. + /// Put simply, this is the application that is launched when the document file is directly double-clicked or when Open is + /// chosen from the file's shortcut menu. This parameter must contain a valid non- null value and is assumed to be of length + /// MAX_PATH. Responsibility for validating the value is left to the programmer. + /// + /// + /// + /// Type: HINSTANCE + /// Returns a value greater than 32 if successful, or a value less than or equal to 32 representing an error. + /// The following table lists possible error values. + /// + /// + /// Return code/value + /// Description + /// + /// + /// SE_ERR_FNF 2 + /// The specified file was not found. + /// + /// + /// SE_ERR_PNF 3 + /// The specified path is invalid. + /// + /// + /// SE_ERR_ACCESSDENIED 5 + /// The specified file cannot be accessed. + /// + /// + /// SE_ERR_OOM 8 + /// The system is out of memory or resources. + /// + /// + /// SE_ERR_NOASSOC 31 + /// There is no association for the specified file type with an executable file. + /// + /// + /// + /// + /// Use FindExecutable for documents. If you want to retrieve the path of an executable file, use the following: + /// Here, pszExecutableName is a pointer to a null-terminated string that specifies the name of the executable file, pszPath is a pointer to the null-terminated string buffer that receives the path to the executable file, and pcchOut is a pointer to a DWORD that specifies the number of characters in the pszPath buffer. When the function returns, pcchOut is set to the number of characters actually placed in the buffer. See AssocQueryString for more information. + /// + /// When FindExecutable returns, the parameter may contain the path to the Dynamic Data Exchange (DDE) server started if a + /// server does not respond to a request to initiate a DDE conversation with the DDE client application. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-findexecutablea + // HINSTANCE FindExecutableA( LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shellapi.h", MSDNShortId = "969edbd9-164e-457f-ab0a-dc4d069bf16b")] + public static extern IntPtr FindExecutable(string lpFile, string lpDirectory, StringBuilder lpResult); + + /// + /// Initializes the network address control window class. + /// + /// + /// Type: BOOL + /// TRUE if the initialization succeeded; or FALSE otherwise. + /// + /// + /// + /// The network address control looks like an edit control and offers the additional functionality of network address verification. + /// The control uses a balloon tip to display error messages. + /// + /// This function initializes class WC_NETADDRESS. If this function returns TRUE, the control can be created. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-initnetworkaddresscontrol + // BOOL InitNetworkAddressControl( ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shellapi.h", MSDNShortId = "52b475e3-7335-4c34-80d7-ccd81af0e0ec")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool InitNetworkAddressControl(); + + /// + /// Adds default properties to the property store as registered for the specified file extension. + /// + /// + /// Type: PCWSTR + /// A pointer to a null-terminated, Unicode string that specifies the extension. + /// + /// + /// Type: IPropertyStore* + /// A pointer to the IPropertyStore interface that defines the default properties to add. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// The list of properties used to set a default value comes from the registry value of the ProgID for the file association of the + /// specified file extension. The list is prefixed by "" and contains the canonical names of the properties to set the default value, + /// such as: "". The possible properties for this list are System.Author, System.Document.DateCreated, and + /// System.Photo.DateTaken. If the value does not exist on the ProgID, this function uses the default found on the value of HKEY_CLASSES_ROOT*. + /// + /// + /// System.Author has the value of the user that performed the action. System.Document.DateCreated and + /// System.Photo.DateTaken use the current date. These three properties are the only ones for which the system provides + /// special defaults. + /// + /// Note that there are several types of properties: + /// + /// Properties that derive from the file system (such as, size and date created) + /// Properties that derive from the file (such as, dimensions and number of pages) + /// Properties that are placed in the file (such as, author and tags) + /// + /// + /// When creating a new file, types one and two are provided just by creating the file. But properties of type three must be set + /// explicitly by a program. The system provides + /// + /// SHAddDefaultPropertiesByExt + /// + /// to provide values for up to three specific properties of type three. Sometimes Windows Explorer uses this API when saving a file + /// for the first time, or when creating a new file after the menu choice + /// + /// New + /// is selected from a shortcut menu. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-shadddefaultpropertiesbyext + // SHSTDAPI SHAddDefaultPropertiesByExt( PCWSTR pszExt, IPropertyStore *pPropStore ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shobjidl.h", MSDNShortId = "ba0fec36-3983-4064-9202-6158af565d9b")] + public static extern HRESULT SHAddDefaultPropertiesByExt([MarshalAs(UnmanagedType.LPWStr)] string pszExt, IPropertyStore pPropStore); + + /// + /// + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable + /// in subsequent versions of Windows.] + /// + /// Adds pages to a property sheet extension array created by SHCreatePropSheetExtArray. + /// + /// + /// Type: HPSXA + /// The array of property sheet handlers returned by SHCreatePropSheetExtArray. + /// + /// + /// Type: LPFNADDPROPSHEETPAGE + /// + /// A pointer to an AddPropSheetPageProc callback function. It is called once for each property sheet handler. The callback function + /// then returns the information needed to add a page to the handler's property sheet. + /// + /// + /// + /// Type: LPARAM + /// A pointer to application-defined data. This data is passed to the callback function specified by . + /// + /// + /// Type: UINT + /// Returns the number of pages actually added. + /// + /// + /// This function should be called only once for the property sheet extension array named in . + /// This function calls each extension's IShellPropSheetExt::AddPages method. See that page for further details. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shaddfrompropsheetextarray + // WINSHELLAPI UINT SHAddFromPropSheetExtArray( HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "e0570cd6-dda2-43e4-8540-58baef37bf18")] + public static extern uint SHAddFromPropSheetExtArray(IntPtr hpsxa, AddPropSheetPageProc lpfnAddPage, IntPtr lParam); + + /// + /// + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable + /// in subsequent versions of Windows. Use + /// + /// CoTaskMemAlloc + /// instead.] + /// + /// + /// Type: SIZE_T + /// The number of bytes of memory to allocate. + /// + /// + /// Type: LPVOID + /// A pointer to the allocated memory. + /// + /// + /// You can free this memory by calling SHFree. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shalloc + // void * SHAlloc( SIZE_T cb ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "621e4335-1484-4111-9cfe-7ae5c6d5c609")] + public static extern IntPtr SHAlloc(SizeT cb); + + /// + /// Sends an appbar message to the system. + /// + /// + /// Type: DWORD + /// Appbar message value to send. This parameter can be one of the following values. + /// ABM_NEW (0x00000000) + /// + /// Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. + /// + /// ABM_REMOVE (0x00000001) + /// Unregisters an appbar, removing the bar from the system's internal list. + /// ABM_QUERYPOS (0x00000002) + /// Requests a size and screen position for an appbar. + /// ABM_SETPOS (0x00000003) + /// Sets the size and screen position of an appbar. + /// ABM_GETSTATE (0x00000004) + /// Retrieves the autohide and always-on-top states of the Windows taskbar. + /// ABM_GETTASKBARPOS (0x00000005) + /// + /// Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, + /// particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered + /// by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and + /// other app bars—the working area available to your application—, use the GetMonitorInfo function. + /// + /// ABM_ACTIVATE (0x00000006) + /// + /// Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by is set to + /// TRUE to activate or FALSE to deactivate. + /// + /// ABM_GETAUTOHIDEBAR (0x00000007) + /// Retrieves the handle to the autohide appbar associated with a particular edge of the screen. + /// ABM_SETAUTOHIDEBAR (0x00000008) + /// Registers or unregisters an autohide appbar for an edge of the screen. + /// ABM_WINDOWPOSCHANGED (0x00000009) + /// Notifies the system when an appbar's position has changed. + /// ABM_SETSTATE (0x0000000A) + /// Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes. + /// ABM_GETAUTOHIDEBAREX (0x0000000B) + /// + /// Windows XP and later: Retrieves the handle to the autohide appbar associated with a particular edge of a particular monitor. + /// + /// ABM_SETAUTOHIDEBAREX (0x0000000C) + /// Windows XP and later: Registers or unregisters an autohide appbar for an edge of a particular monitor. + /// + /// + /// Type: PAPPBARDATA + /// + /// A pointer to an APPBARDATA structure. The content of the structure on entry and on exit depends on the value set in the + /// parameter. See the individual message pages for specifics. + /// + /// + /// + /// Type: UINT_PTR + /// + /// This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar + /// message sent. Links to those documents are given in the See Also section. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shappbarmessage + // UINT_PTR SHAppBarMessage( DWORD dwMessage, PAPPBARDATA pData ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shellapi.h", MSDNShortId = "173d6eff-b33b-4d7d-bedd-5ebfb1e45954")] + public static extern UIntPtr SHAppBarMessage(ABM dwMessage, ref APPBARDATA pData); + /// /// Performs an operation on a specified file. /// @@ -315,6 +1014,96 @@ namespace Vanara.PInvoke public static extern IntPtr SHGetFileInfo(PIDL itemIdList, FileAttributes dwFileAttributes, ref SHFILEINFO psfi, int cbFileInfo, SHGFI uFlags); + /// + /// Contains information about a system appbar message. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi-_appbardata typedef struct _AppBarData { DWORD cbSize; + // HWND hWnd; UINT uCallbackMessage; UINT uEdge; RECT rc; LPARAM lParam; } APPBARDATA, *PAPPBARDATA; + [PInvokeData("shellapi.h", MSDNShortId = "cf86fe15-4beb-49b7-b73e-2ad61cedc3f8")] + public struct APPBARDATA + { + /// + /// Type: DWORD + /// The size of the structure, in bytes. + /// + public uint cbSize; + /// + /// Type: HWND + /// + /// The handle to the appbar window. Not all messages use this member. See the individual message page to see if you need to + /// provide an hWind value. + /// + /// + public IntPtr hWnd; + /// + /// Type: LPARAM + /// A message-dependent value. This member is used with these messages: + /// ABM_SETAUTOHIDEBAR + /// ABM_SETAUTOHIDEBAREX + /// ABM_SETSTATE + /// See the individual message pages for details. + /// + public IntPtr lParam; + + /// + /// Type: RECT + /// A RECT structure whose use varies depending on the message: + /// + /// + /// ABM_GETTASKBARPOS, ABM_QUERYPOS, ABM_SETPOS: The bounding rectangle, in screen coordinates, of an appbar or the Windows taskbar. + /// + /// + /// ABM_GETAUTOHIDEBAREX, ABM_SETAUTOHIDEBAREX: The monitor on which the operation is being performed. This information can be + /// retrieved through the GetMonitorInfo function. + /// + /// + /// + public RECT rc; + + /// + /// Type: UINT + /// + /// An application-defined message identifier. The application uses the specified identifier for notification messages that it + /// sends to the appbar identified by the hWnd member. This member is used when sending the ABM_NEW message. + /// + /// + public uint uCallbackMessage; + /// + /// Type: UINT + /// A value that specifies an edge of the screen. This member is used when sending one of these messages: + /// ABM_GETAUTOHIDEBAR + /// ABM_SETAUTOHIDEBAR + /// ABM_GETAUTOHIDEBAREX + /// ABM_SETAUTOHIDEBAREX + /// ABM_QUERYPOS + /// ABM_SETPOS + /// This member can be one of the following values. + /// ABE_BOTTOM + /// Bottom edge. + /// ABE_LEFT + /// Left edge. + /// ABE_RIGHT + /// Right edge. + /// ABE_TOP + /// Top edge. + /// + public ABE uEdge; + } + + /// Defines information used by AssocCreateForClasses to retrieve an IQueryAssociations interface for a given file association. + [PInvokeData("shellapi.h", MSDNShortId = "1d1a963f-7ebb-4ba6-9a97-795c8ef11ae4")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct ASSOCIATIONELEMENT + { + /// + /// Where to obtain association data and the form the data is stored in. One of the following values from the ASSOCCLASS enumeration. + /// + public ASSOCCLASS ac; + /// A registry key that specifies a class that contains association information. + public IntPtr hkClass; + /// A pointer to the name of a class that contains association information. + public string pszClass; + } /// /// Contains information used by ShellExecuteEx. /// diff --git a/PInvoke/Shell32/ShlObj.cs b/PInvoke/Shell32/ShlObj.cs index 6bf8300d..4bb8e956 100644 --- a/PInvoke/Shell32/ShlObj.cs +++ b/PInvoke/Shell32/ShlObj.cs @@ -1,11 +1,14 @@ using System; using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; using System.Security; using System.Text; using Vanara.InteropServices; using static Vanara.PInvoke.AdvApi32; using static Vanara.PInvoke.ComCtl32; using static Vanara.PInvoke.Kernel32; +using static Vanara.PInvoke.Ole32; +using static Vanara.PInvoke.ShlwApi; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedParameter.Global @@ -23,6 +26,16 @@ namespace Vanara.PInvoke // Defined in wingdi.h private const int LF_FACESIZE = 32; + /// A flag that controls how PifMgr_CloseProperties operates. + [PInvokeData("shlobj_core.h", MSDNShortId = "fd50d4f8-87c8-4162-9e88-3c8592b929fa")] + public enum CLOSEPROPS + { + /// No options specified. + CLOSEPROPS_NONE = 0x0000, + /// Abandon cached data. + CLOSEPROPS_DISCARD = 0x0001 + } + /// Used for options in SHOpenFolderAndSelectItems. [PInvokeData("Shlobj.h", MSDNShortId = "bb762232")] public enum OFASI : uint @@ -43,6 +56,56 @@ namespace Vanara.PInvoke OFASI_OPENDESKTOP = 2 } + /// A flag that controls how PifMgr_OpenProperties operates. + [PInvokeData("shlobj_core.h", MSDNShortId = "0bc11528-7278-4765-b3cb-671ba82c9155")] + public enum OPENPROPS + { + /// No options specified. + OPENPROPS_NONE = 0x0000, + /// + /// Ignore any existing .pif files and get the properties from win.ini or _Default.pif. This flag is ignored on Windows NT, + /// Windows 2000, and Windows XP. + /// + OPENPROPS_INHIBITPIF = 0x8000 + } + + /// Return values for PathCleanupSpec. + [PInvokeData("shlobj_core.h", MSDNShortId = "593fd2b7-44ae-4309-a185-97e42f3cc0fa")] + [Flags] + public enum PCS : uint + { + /// The cleaned path is not a valid file name. This flag is always returned in conjunction with PCS_PATHTOOLONG. + PCS_FATAL = 0x80000000, + /// Replaced one or more invalid characters. + PCS_REPLACEDCHAR = 0x00000001, + /// Removed one or more invalid characters. + PCS_REMOVEDCHAR = 0x00000002, + /// The returned path is truncated. + PCS_TRUNCATED = 0x00000004, + /// + /// The function failed because the input path specified at is too long to allow the formation of a valid file name from . When this + /// flag is returned, it is always accompanied by the PCS_FATAL flag. + /// + PCS_PATHTOOLONG = 0x00000008, + } + + /// Flags for PathResolve. + [PInvokeData("shlobj_core.h", MSDNShortId = "84bf0b56-513f-4ac6-b2cf-11f0c471da1e")] + [Flags] + public enum PRF + { + /// Return TRUE if the file's existence is verified; otherwise FALSE. + PRF_VERIFYEXISTS = 0x0001, + /// Look for the specified path with the following extensions appended: .pif, .com, .bat, .cmd, .lnk, and .exe. + PRF_TRYPROGRAMEXTENSIONS = 0x0002 | PRF_VERIFYEXISTS, + /// Look first in the directory or directories specified by dirs. + PRF_FIRSTDIRDEF = 0x0004, + /// Ignore .lnk files. + PRF_DONTFINDLNK = 0x0008, + /// Require an absolute (full) path. + PRF_REQUIREABSOLUTE = 0x0010 + } + /// Flags that direct the handling of the item from which you're retrieving the info tip text. This value is commonly zero (QITIPF_DEFAULT). [PInvokeData("Shlobj.h", MSDNShortId = "bb761357")] public enum QITIP @@ -66,6 +129,18 @@ namespace Vanara.PInvoke QITIPF_SINGLELINE = 0x00000010, } + /// Indicates whether to enable or disable Async Register and Deregister for SHChangeNotifyRegisterThread. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/ne-shlobj_core-scnrt_status + // typedef enum SCNRT_STATUS { SCNRT_ENABLE , SCNRT_DISABLE } ; + [PInvokeData("shlobj_core.h", MSDNShortId = "31fd993b-d8cb-40cc-9f31-15711dba1b10")] + public enum SCNRT_STATUS + { + /// Enable Async Register and Deregister for SHChangeNotifyRegisterThread. + SCNRT_ENABLE, + /// Disable Async Register and Deregister for SHChangeNotifyRegisterThread. + SCNRT_DISABLE, + } + /// /// Indicates the interpretation of the data passed by SHAddToRecentDocs in its pv parameter to identify the item whose usage statistics are being tracked. /// @@ -432,6 +507,887 @@ namespace Vanara.PInvoke CSIDL_WINDOWS = 0x0024, // GetWindowsDirectory() } + /// + /// Retrieves the value for a given property key using the file association information provided by the Namespace Extensions. + /// + /// + /// Type: IShellFolder* + /// A pointer to the shell folder for which the details of the property key of the file association are being retrieved. + /// + /// + /// Type: PCUITEMID_CHILD + /// The PIDL of the child item for which the file associations are being requested. + /// + /// + /// Type: PROPERTYKEY* + /// A pointer to the property key that is being retrieved. + /// + /// + /// Type: VARIANT* + /// When this function returns, contains the details of the given property key. + /// + /// + /// Type: BOOL* + /// When this function returns, contains a flag that is TRUE if the property key was found, otherwise FALSE. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// This function is to be used only by implementers of IShellFolder Namespace Extensions. Other calling applications should use + /// IShellFolder2::GetDetailsEx to get a value for a PROPERTYKEY. This function is to be used by implementers of IShellFolder + /// Namespace Extensions. + /// + /// The provided namespace extension must support the use of this API in one of the following three ways. + /// + /// + /// If the provided Namespace Extensions supports retrieving an IQueryAssociations interface for the item by implementing + /// IShellFolder::GetUIObjectOf(..., IID_IQueryAssociations, ...), then AssocGetDetailsOfPropKey will use the provided + /// file associations API to retrieve the value for the property key. + /// + /// + /// If the provided namespace extension returns SFGAO_FILESYSTEM for the item from IShellFolder::GetAttributesOf and provides + /// a parsing name for the item, then AssocGetDetailsOfPropKey will use the standard file system associations to retrieve the + /// value for the property key. + /// + /// + /// If the provided namespace extension returns SFGAO_FOLDER | SFGAO_BROWSABLE for the item from + /// IShellFolder::GetAttributesOf, then AssocGetDetailsOfPropKey will use the file association for folders ( + /// ASSOCCLASS_FOLDER) to retrieve the value for the property key. + /// + /// + /// + /// If the ShellFolder being implemented contains items that are extensible through the file associations mechanism, then you can use + /// this function to retrieve + /// + /// PropertyKeys + /// + /// that are declared for a given file association. For example, if a given Shell folder drives a details pane and you want the + /// properties displayed in that pane to be governed by third party file name extensions, then you can use this function to return + /// + /// PKEY_PropList_PreviewDetails + /// + /// . This key has a value that is declared in the registry for that file name extension with a semicolon delimited list of + /// properties. There is a list of file name extension defined properties in the registry. This list includes but is not limited to + /// the following: + /// + /// + /// PKEY_PropList_PreviewDetails + /// PKEY_PropList_PreviewTitle + /// PKEY_PropList_FullDetails + /// PKEY_PropList_TileInfo + /// PKEY_PropList_ExtendedTileInfo + /// PKEY_PropList_InfoTip + /// PKEY_PropList_QuickTip + /// PKEY_PropList_FileOperationPrompt + /// PKEY_PropList_ConflictPrompt + /// PKEY_PropList_SetDefaultsFor + /// PKEY_PropList_NonPersonal + /// PKEY_NewMenuPreferredTypes + /// PKEY_NewMenuAllowedTypes + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-assocgetdetailsofpropkey + // SHSTDAPI AssocGetDetailsOfPropKey( IShellFolder *psf, PCUITEMID_CHILD pidl, const PROPERTYKEY *pkey, VARIANT *pv, BOOL *pfFoundPropKey ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "f13af5f4-1b6a-419c-a042-e05c9ec51d02")] + public static extern HRESULT AssocGetDetailsOfPropKey(IShellFolder psf, PIDL pidl, ref PROPERTYKEY pkey, ref object pv, [MarshalAs(UnmanagedType.Bool)] ref bool pfFoundPropKey); + + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable in subsequent versions of Windows.]Creates an Open dialog box so that the user can specify the drive, directory, and name of a file to open.Type: HWNDA handle to the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner.Type: PWSTRA null-terminated Unicode string that contains a file name used to initialize the File Name edit control. This string corresponds to the OPENFILENAME structure's lpstrFile member and is used in exactly the same way.Type: UINTThe number of characters in , including the terminating null character.Type: PCWSTRThe fully qualified file path of the initial directory. This string corresponds to the OPENFILENAME structure's lpstrInitialDir member and is used in exactly the same way.Type: PCWSTRA null-terminated Unicode string that contains the default file name extension. This extension is added to if the user does not specify an extension. The string should not contain any '.' characters. If this string is NULL and the user fails to type an extension, no extension is appended.Type: PCWSTRA null-terminated Unicode string that defines the filter. This string corresponds to the OPENFILENAME structure's lpstrFilter member and is used in exactly the same way.TBDType: BOOLIf the user specifies a file name and clicks OK, the return value is TRUE. The buffer that points to contains the full path and file name that the user specifies. If the user cancels or closes the Open dialog box or an error occurs, the return value is FALSE. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj/nf-shlobj-getfilenamefrombrowse + // BOOL GetFileNameFromBrowse( HWND hwnd, PWSTR pszFilePath, UINT cchFilePath, PCWSTR pszWorkingDir, PCWSTR pszDefExt, PCWSTR pszFilters, PCWSTR pszTitle ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj.h", MSDNShortId = "1f075051-18c8-4ec2-b010-f983ba2d3303")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetFileNameFromBrowse(HandleRef hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszFilePath, uint cchFilePath, [MarshalAs(UnmanagedType.LPWStr)] string pszWorkingDir, [MarshalAs(UnmanagedType.LPWStr)] string pszDefExt, [MarshalAs(UnmanagedType.LPWStr)] string pszFilters, [MarshalAs(UnmanagedType.LPWStr)] string pszTitle); + + /// + /// Appends or prepends an SHITEMID structure to an ITEMIDLIST structure. + /// + /// + /// Type: PIDLIST_RELATIVE + /// A pointer to an ITEMIDLIST structure. When the function returns, the SHITEMID structure specified by is appended or prepended. + /// + /// + /// Type: LPSHITEMID + /// A pointer to a SHITEMID structure to be appended or prepended to . + /// + /// + /// Type: BOOL + /// Value that is set to TRUE to append to . Set this value to FALSE to prepend to . + /// + /// + /// Type: PIDLIST_RELATIVE + /// Returns the ITEMIDLIST structure specified by , with appended or prepended. Returns NULL on failure. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-ilappendid + // PIDLIST_RELATIVE ILAppendID( PIDLIST_RELATIVE pidl, LPCSHITEMID pmkid, BOOL fAppend ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "d1bb5993-fe23-42d4-a2c5-8e54e6e37d09")] + public static extern IntPtr ILAppendID(IntPtr pidl, ref SHITEMID pmkid, [MarshalAs(UnmanagedType.Bool)] bool fAppend); + + /// Determines whether a specified ITEMIDLIST structure is the child of another ITEMIDLIST structure.Type: PCIDLIST_ABSOLUTEA pointer to the parent ITEMIDLIST structure.Type: PCIDLIST_ABSOLUTEA pointer to the child ITEMIDLIST structure.Type: PUIDLIST_RELATIVEReturns a pointer to the child's simple ITEMIDLIST structure if is a child of . The returned structure consists of , minus the SHITEMID structures that make up . Returns NULL if is not a child of .Note The returned pointer is a pointer into the existing parent structure. It is an alias for . No new memory is allocated in association with the returned pointer. It is not the caller's responsibility to free the returned value. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-ilfindchild + // PUIDLIST_RELATIVE ILFindChild( PIDLIST_ABSOLUTE pidlParent, PCIDLIST_ABSOLUTE pidlChild ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "4f07e989-ae74-4cf4-b3d9-0f59f2653095")] + public static extern IntPtr ILFindChild(IntPtr pidlParent, IntPtr pidlChild); + + /// + /// [ + /// ILLoadFromStreamEx(IStream*, PIDLIST_ABSOLUTE*) + /// + /// is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in + /// subsequent versions.] + /// + /// Loads an absolute ITEMIDLIST from an IStream. + /// + /// + /// Type: IStream* + /// A pointer to the IStream interface from which the absolute ITEMIDLIST loads. + /// + /// + /// TBD + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// For use where STRICT_TYPED_ITEMIDS is defined. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-illoadfromstreamex + // SHSTDAPI ILLoadFromStreamEx( IStream *pstm, PIDLIST_RELATIVE *pidl ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "6fb735b6-a8c3-439e-9f20-4fda8f008b28")] + public static extern HRESULT ILLoadFromStreamEx(IStream pstm, out IntPtr pidl); + + /// + /// Saves an ITEMIDLIST structure to a stream. + /// + /// + /// Type: IStream * + /// A pointer to the IStream interface where the ITEMIDLIST is saved. + /// + /// + /// Type: PCUIDLIST_RELATIVE + /// A pointer to the ITEMIDLIST structure to be saved. + /// + /// + /// Type: HRESULT + /// Returns S_OK if successful, or a COM error value otherwise. + /// + /// + /// The stream must be opened for writing, or ILSaveToStream returns an error. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-ilsavetostream + // SHSTDAPI ILSaveToStream( IStream *pstm, PCUIDLIST_RELATIVE pidl ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "40d5ce57-58dc-4c79-8fe6-5412e3d7dc64")] + public static extern HRESULT ILSaveToStream(IStream pstm, IntPtr pidl); + + /// + /// + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable + /// in subsequent versions of Windows. Use + /// + /// GetDriveType + /// or + /// WNetGetConnection + /// instead.] + /// Tests whether a drive is a network drive. + /// + /// + /// Type: int + /// An integer that indicates which drive letter you want to test. Set it to 0 for A:, 1 for B:, and so on. + /// + /// + /// Type: int + /// This function returns one of the following values. + /// + /// + /// Return value + /// Description + /// + /// + /// 0 + /// The specified drive is not a network drive. + /// + /// + /// 1 + /// The specified drive is a network drive that is properly connected. + /// + /// + /// 2 + /// The specified drive is a network drive that is disconnected or in an error state. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-isnetdrive + // int IsNetDrive( int iDrive ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "44e02665-648a-4cf0-9dc0-038e54d08a49")] + public static extern int IsNetDrive(int iDrive); + + /// + /// [IsUserAnAdmin is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in + /// subsequent versions.] + /// + /// Tests whether the current user is a member of the Administrator's group. + /// + /// + /// Type: BOOL + /// Returns TRUE if the user is a member of the Administrator's group; otherwise, FALSE. + /// + /// + /// + /// This function is a wrapper for CheckTokenMembership. It is recommended to call that function directly to determine Administrator + /// group status rather than calling IsUserAnAdmin. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-isuseranadmin + // BOOL IsUserAnAdmin( ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "fe698d32-32f6-4b2b-ad0c-5d9ec815177f")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsUserAnAdmin(); + + /// + /// + /// [OpenRegStream is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions. Instead, use SHOpenRegStream2 or SHOpenRegStream.] + /// + /// Opens a registry value and supplies an IStream interface that can be used to read from or write to the value. + /// + /// + /// Type: HKEY + /// A handle to the key that is currently open. + /// + /// + /// Type: PCWSTR + /// A null-terminated Unicode string that specifies the name of the subkey. + /// + /// + /// Type: PCWSTR + /// A null-terminated Unicode string that specifies the value to be accessed. + /// + /// + /// Type: DWORD + /// The type of access for the stream. This can be one of the following values. + /// STGM_READ + /// Open the stream for reading. + /// STGM_WRITE + /// Open the stream for writing. + /// STGM_READWRITE + /// Open the stream for reading and writing. + /// + /// + /// Type: IStream* + /// Returns the address of an IStream interface if successful, or NULL otherwise. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-openregstream + // IStream * OpenRegStream( HKEY hkey, PCWSTR pszSubkey, PCWSTR pszValue, DWORD grfMode ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "e1e35c94-84ac-4aa1-b2a1-47b37a7f224e")] + public static extern IStream OpenRegStream(IntPtr hkey, [MarshalAs(UnmanagedType.LPWStr)] string pszSubkey, [MarshalAs(UnmanagedType.LPWStr)] string pszValue, STGM grfMode); + + /// + /// [PathCleanupSpec is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in + /// subsequent versions.] + /// + /// + /// Removes illegal characters from a file or directory name. Enforces the 8.3 filename format on drives that do not support long + /// file names. + /// + /// + /// + /// Type: PCWSTR + /// + /// A pointer to a null-terminated buffer that contains the fully qualified path of the directory that will contain the file or + /// directory named at . The path must not exceed MAX_PATH characters in length, including the terminating null character. This path + /// is not altered. + /// + /// This value can be NULL. + /// + /// + /// Type: PWSTR + /// + /// A pointer to a null-terminated buffer that contains the file or directory name to be cleaned. In the case of a file, include the + /// file's extension. Note that because '' is considered an invalid character and will be removed, this buffer cannot contain a path + /// more than one directory deep. + /// + /// On exit, the buffer contains a null-terminated string that includes the cleaned name. + /// This buffer should be at least MAX_PATH characters in length to avoid the possibility of a buffer overrun. + /// + /// + /// Type: int + /// Returns one or more of the following values. + /// + /// + /// Return code + /// Description + /// + /// + /// PCS_REPLACEDCHAR + /// Replaced one or more invalid characters. + /// + /// + /// PCS_REMOVEDCHAR + /// Removed one or more invalid characters. + /// + /// + /// PCS_TRUNCATED + /// The returned path is truncated. + /// + /// + /// PCS_PATHTOOLONG + /// + /// The function failed because the input path specified at is too long to allow the formation of a valid file name from . When this + /// flag is returned, it is always accompanied by the PCS_FATAL flag. + /// + /// + /// + /// PCS_FATAL + /// The cleaned path is not a valid file name. This flag is always returned in conjunction with PCS_PATHTOOLONG. + /// + /// + /// + /// + /// The following are considered invalid characters in all names. + /// + /// Control characters are also considered invalid. If long file names are not supported, the semi-colon (;) and comma (,) characters + /// are also invalid. + /// + /// + /// The drive named in is checked to determine whether its file system supports long file names. If it does not, the name at is + /// truncated to the 8.3 format and the PCS_TRUNCATED value returned. If is NULL, the drive on which Windows is installed is + /// used to determine long file name support. + /// + /// + /// If the full path—the number of characters in the path at plus the number of characters in the cleaned name at —exceeds MAX_PATH – + /// 1 (to account for the terminating null character), the function returns PCS_PATHTOOLONG. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pathcleanupspec + // int PathCleanupSpec( PCWSTR pszDir, PWSTR pszSpec ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "593fd2b7-44ae-4309-a185-97e42f3cc0fa")] + public static extern PCS PathCleanupSpec([MarshalAs(UnmanagedType.LPWStr)] string pszDir, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszSpec); + /// + /// [PathGetShortPath is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in + /// subsequent versions.] + /// + /// Retrieves the short path form of a specified input path. + /// + /// + /// Type: PWSTR + /// + /// A pointer to a null-terminated, Unicode string that contains the long path. When the function returns, it contains the equivalent + /// short path. + /// + /// + /// + /// This function does not return a value. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pathgetshortpath + // void PathGetShortPath( PWSTR pszLongPath ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "f374a575-3fbf-4bed-aa76-76ed81e01d60")] + public static extern void PathGetShortPath([MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszLongPath); + + /// + /// + /// [PathIsExe is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable + /// in subsequent versions.] + /// + /// Determines whether a file is an executable by examining the file name extension. + /// + /// + /// TBD + /// + /// + /// Type: BOOL + /// Returns TRUE if the file name extension is .cmd, .bat, .pif, .scf, .exe, .com, or .scr; otherwise, FALSE. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pathisexe + // BOOL PathIsExe( PCWSTR pszPath ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "54e9dae7-f9c4-48b8-9b91-32ed21365fb7")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PathIsExe([MarshalAs(UnmanagedType.LPWStr)] string pszPath); + + /// + /// + /// [PathIsSlow is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable + /// in subsequent versions.] + /// + /// Determines whether a file path is a high-latency network connection. + /// + /// + /// Type: LPCTSTR + /// A pointer to a null-terminated string that contains the fully qualified path of the file. + /// + /// + /// TBD + /// + /// + /// Type: BOOL + /// Returns TRUE if the connection is high-latency; otherwise, FALSE. + /// + /// + /// + /// A path is considered slow if the MultinetGetConnectionPerformance function returns a dwSpeed of 400 or less in its + /// NETCONNECTINFOSTRUCT structure—this is the speed of the media to the network resource, in 100 bits-per-second (bps)—or if + /// FILE_ATTRIBUTE_OFFLINE is set on the file. + /// + /// Note that network conditions can impact function performance time. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj/nf-shlobj-pathisslowa + // BOOL PathIsSlowA( LPCSTR pszFile, DWORD dwAttr ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shlobj.h", MSDNShortId = "f848a098-9248-453b-a957-77c35d70e528")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PathIsSlow(string pszFile, uint dwAttr); + + /// + /// Creates a unique path name from a template. + /// + /// + /// Type: PWSTR + /// + /// A buffer that receives a null-terminated Unicode string that contains the unique path name. It should be at least MAX_PATH + /// characters in length. + /// + /// + /// + /// Type: UINT + /// The number of characters in the buffer pointed to by . + /// + /// + /// Type: PCWSTR + /// + /// A null-terminated Unicode string that contains a template that is used to construct the unique name. This template is used for + /// drives that require file names with the 8.3 format. This string should be no more than MAX_PATH characters in length, including + /// the terminating null character. + /// + /// + /// + /// Type: PCWSTR + /// + /// A null-terminated Unicode string that contains a template that is used to construct the unique name. This template is used for + /// drives that support long file names. This string should be no more than MAX_PATH characters in length, including the terminating + /// null character. + /// + /// + /// + /// Type: PCWSTR + /// + /// A null-terminated string that contains the directory in which the new file resides. This string should be no more than MAX_PATH + /// characters in length, including the terminating null character. + /// + /// + /// + /// Type: BOOL + /// Returns TRUE if successful; otherwise, FALSE. + /// + /// + /// + /// This function generates a new unique file name based on the templates specified by , for drives that require the 8.3 format, and + /// for drives that support long file names. For example, if you specify "My New Filename" for , PathMakeUniqueName returns + /// names such as "My New Filename (1)", "My New Filename (2)", and so on. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pathmakeuniquename + // BOOL PathMakeUniqueName( PWSTR pszUniqueName, UINT cchMax, PCWSTR pszTemplate, PCWSTR pszLongPlate, PCWSTR pszDir ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "8456ae0c-e83c-43d0-a86a-1861a373d237")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PathMakeUniqueName([MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszUniqueName, uint cchMax, [MarshalAs(UnmanagedType.LPWStr)] string pszTemplate, [MarshalAs(UnmanagedType.LPWStr)] string pszLongPlate, [MarshalAs(UnmanagedType.LPWStr)] string pszDir); + + /// + /// + /// [PathResolve is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions.] + /// + /// Converts a relative or unqualified path name to a fully qualified path name. + /// + /// + /// Type: PWSTR + /// + /// A null-terminated Unicode string that contains the path to resolve. When the function returns, the string contains the + /// corresponding fully qualified path. This buffer should be at least MAX_PATH characters long. + /// + /// + /// + /// Type: PZPCWSTR + /// + /// A pointer to an optional null-terminated array of directories to be searched first in the case that the path cannot be resolved + /// from . This value can be NULL. + /// + /// + /// + /// Type: UINT + /// Flags that specify how the function operates. + /// PRF_VERIFYEXISTS + /// Return TRUE if the file's existence is verified; otherwise FALSE. + /// PRF_TRYPROGRAMEXTENSIONS + /// Look for the specified path with the following extensions appended: .pif, .com, .bat, .cmd, .lnk, and .exe. + /// PRF_FIRSTDIRDEF + /// Look first in the directory or directories specified by . + /// PRF_DONTFINDLNK + /// Ignore .lnk files. + /// PRF_REQUIREABSOLUTE + /// Require an absolute (full) path. + /// + /// + /// Type: int + /// + /// Returns TRUE, unless PRF_VERIFYEXISTS is set. If that flag is set, the function returns TRUE if the file is + /// verified to exist and FALSE otherwise. It also sets an ERROR_FILE_NOT_FOUND error code that you can retrieve by calling GetLastError. + /// + /// + /// + /// + /// A FALSE return value does not necessarily mean that the file does not exist. It might mean that the function is simply + /// unable to find the file from the supplied information. + /// + /// If PathResolve cannot resolve the path specified in , it calls PathFindOnPath using and as the parameters. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pathresolve + // int PathResolve( PWSTR pszPath, PZPCWSTR dirs, UINT fFlags ); + [DllImport(Lib.Shell32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("shlobj_core.h", MSDNShortId = "84bf0b56-513f-4ac6-b2cf-11f0c471da1e")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PathResolve(StringBuilder pszPath, string[] dirs, PRF fFlags); + /// + /// Creates a unique filename based on an existing filename. + /// + /// + /// Type: PWSTR + /// + /// A string buffer that receives a null-terminated Unicode string that contains the fully qualified path of the unique file name. + /// This buffer should be at least MAX_PATH characters long to avoid causing a buffer overrun. + /// + /// + /// + /// Type: PCWSTR + /// + /// A null-terminated Unicode string that contains the fully qualified path of folder that will contain the new file. If is set to + /// NULL, this string must contain a full destination path, ending with the long file name that the new file name will be base on. + /// + /// + /// + /// Type: PCWSTR + /// + /// A null-terminated Unicode string that contains the short file name that the unique name will be based on. Set this value to + /// NULL to create a name based on the long file name. + /// + /// + /// + /// Type: PCWSTR + /// A null-terminated Unicode string that contains the long file name that the unique name will be based on. + /// + /// + /// Type: BOOL + /// Returns TRUE if a unique name was successfully created; otherwise FALSE. + /// + /// + /// + /// If the generated path exceeds MAX_PATH characters, this function may return a truncated string in + /// PathYetAnotherMakeUniqueName. In that case, the function returns FALSE. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pathyetanothermakeuniquename + // BOOL PathYetAnotherMakeUniqueName( PWSTR pszUniqueName, PCWSTR pszPath, PCWSTR pszShort, PCWSTR pszFileSpec ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("shlobj_core.h", MSDNShortId = "1f76ecfa-6f2f-4dde-b05e-4252c92660d9")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PathYetAnotherMakeUniqueName(StringBuilder pszUniqueName, string pszPath, string pszShort, string pszFileSpec); + + /// + /// + /// [PickIconDlg is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions.] + /// + /// + /// Displays a dialog box that allows the user to choose an icon from the selection available embedded in a resource such as an + /// executable or DLL file. + /// + /// + /// + /// Type: HWND + /// The handle of the parent window. This value can be NULL. + /// + /// + /// Type: PWSTR + /// + /// A pointer to a string that contains the null-terminated, fully qualified path of the default resource that contains the icons. If + /// the user chooses a different resource in the dialog, this buffer contains the path of that file when the function returns. This + /// buffer should be at least MAX_PATH characters in length, or the returned path may be truncated. You should verify that the path + /// is valid before using it. + /// + /// + /// + /// Type: UINT + /// The number of characters in , including the terminating NULL character. + /// + /// + /// Type: int* + /// + /// A pointer to an integer that on entry specifies the index of the initial selection and, when this function returns successfully, + /// receives the index of the icon that was selected. + /// + /// + /// + /// Type: int + /// Returns 1 if successful; otherwise, 0. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pickicondlg + // int PickIconDlg( HWND hwnd, PWSTR pszIconPath, UINT cchIconPath, int *piIconIndex ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "3dfcda10-26d8-495d-8c92-7ff16da098c1")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PickIconDlg(HandleRef hwnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, uint cchIconPath, ref int piIconIndex); + + /// + /// [PifMgr_CloseProperties is available for use in the operating systems specified in the Requirements section.It may be altered or unavailable in subsequent versions.] + /// Closes application properties that were opened with PifMgr_OpenProperties. + /// A handle to the application's properties. This parameter should be set to the value that is returned by PifMgr_OpenProperties. + /// A flag that specifies how the function operates. + /// Returns NULL if successful. If unsuccessful, the functions returns the handle to the application properties that was passed as hProps. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pifmgr_closeproperties + // HANDLE PifMgr_CloseProperties(HANDLE hProps, UINT flOpt); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "fd50d4f8-87c8-4162-9e88-3c8592b929fa")] + public static extern IntPtr PifMgr_CloseProperties(IntPtr hProps, CLOSEPROPS flOpt); + + /// + /// [PifMgr_GetProperties is available for use in the operating systems specified in the Requirements section.It may be altered or unavailable in subsequent versions.] + /// Returns a specified block of data from a .pif file. + /// A handle to an application's properties. This parameter should be set to the value that is returned by PifMgr_OpenProperties. + /// A null-terminated string that contains the property group name. It can be one of the following, or any other name that corresponds to a valid .pif extension. + /// When this function returns, contains a pointer to a PROPPRG structure. + /// The size of the buffer, in bytes, pointed to by lpProps. + /// Set this parameter to GETPROPS_NONE. + /// Returns NULL if successful. If unsuccessful, the function returns the handle to the application properties that were passed as hProps. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pifmgr_getproperties + // int PifMgr_GetProperties( HANDLE hProps, PCSTR pszGroup, void* lpProps, int cbProps, UINT flOpt ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Ansi)] + [PInvokeData("shlobj_core.h")] + public static extern int PifMgr_GetProperties(IntPtr hProps, string pszGroup, IntPtr lpProps, int cbProps, uint flOpt = 0); + + /// + /// + /// [PifMgr_OpenProperties is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions.] + /// + /// Opens the .pif file associated with a Microsoft MS-DOS application, and returns a handle to the application's properties. + /// + /// + /// Type: PCWSTR + /// A null-terminated Unicode string that contains the application's name. + /// + /// + /// TBD + /// + /// + /// Type: UINT + /// + /// A handle to the application's .inf file. Set this value to zero if there is no .inf file. Set this value to -1 to prevent the + /// .inf file from being processed. + /// + /// + /// + /// Type: UINT + /// A flag that controls how the function operates. + /// OPENPROPS_INHIBITPIF + /// + /// Ignore any existing .pif files and get the properties from win.ini or _Default.pif. This flag is ignored on Windows NT, Windows + /// 2000, and Windows XP. + /// + /// OPENPROPS_NONE + /// No options specified. + /// + /// + /// Type: HANDLE + /// Returns a handle to the application's properties. Use this handle when you call the related .pif functions. + /// + /// + /// + /// You should not think of PifMgr_OpenProperties as a function that opens a file somewhere. The .pif file does not remain + /// open after this call. It is more useful to think of the function as a property structure allocator that you can initialize using + /// disk data. The primary reason why this function fails is because of low memory or inability to open the specified .pif file. + /// + /// + /// If no .pif file exists, the function still allocates a data block in memory and initializes it with data from _Default.pif or its + /// internal defaults. If the function looks for a .pif file name but does not find it, it constructs a name and saves it in its + /// internal .pif data structure. This guarantees that if PifMgr_SetProperties is called, the data is saved to disk. + /// + /// If the function does not find the .pif file, it searches for it in the following order. + /// + /// Searches the current directory. + /// Searches the specified directory. + /// Searches in .pif directory. + /// Searches the folders specified by the PATH environment variable. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pifmgr_openproperties + // HANDLE PifMgr_OpenProperties( PCWSTR pszApp, PCWSTR pszPIF, UINT hInf, UINT flOpt ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "0bc11528-7278-4765-b3cb-671ba82c9155")] + public static extern IntPtr PifMgr_OpenProperties([MarshalAs(UnmanagedType.LPWStr)] string pszApp, [MarshalAs(UnmanagedType.LPWStr)] string pszPIF, uint hInf, OPENPROPS flOpt); + /// + /// [PifMgr_SetProperties is available for use in the operating systems specified in the Requirements section.It may be altered or unavailable in subsequent versions.] + /// Assigns values to a block of data from a .pif file. + /// A handle to the application's properties. This parameter should be set to the value that is returned by PifMgr_OpenProperties. + /// A null-terminated ANSI string containing the property group name. It can be one of the following, or any other name that corresponds to a valid .pif extension. + /// A property group record buffer that holds the data. + /// The size of the buffer, in bytes, pointed to by lpProps. + /// Always SETPROPS_NONE. + /// Returns the amount of information transferred, in bytes. Returns zero if the group cannot be found or an error occurs. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-pifmgr_setproperties + // int PifMgr_SetProperties(HANDLE hProps, PCSTR pszGroup, const void* lpProps, int cbProps, UINT flOpt ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Ansi)] + [PInvokeData("shlobj_core.h")] + public static extern int PifMgr_SetProperties(IntPtr hProps, string pszGroup, IntPtr lpProps, int cbProps, uint flOpt = 0); + + /// [ReadCabinetState is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.]Fills a CABINETSTATE structure with information from the registry.Type: CABINETSTATE*When this function returns, contains a pointer to a CABINETSTATE structure that contains either information pulled from the registry or default information.Type: intThe size of the structure pointed to by , in bytes.Type: BOOLReturns TRUE if the returned structure contains information from the registry. Returns FALSE if the structure contains default information. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-readcabinetstate + // BOOL ReadCabinetState( CABINETSTATE *pcs, int cLength ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "0f0c6a10-588f-4c79-b73b-cf0bf9336ffc")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool ReadCabinetState(ref CABINETSTATE pcs, int cLength); + + /// + /// + /// [RealDriveType is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions.] + /// + /// Determines the drive type based on the drive number. + /// + /// + /// Type: int + /// The number of the drive that you want to test. "A:" corresponds to 0, "B:" to 1, and so on. + /// + /// + /// Type: BOOL + /// Reserved. Must be set to 0. + /// + /// + /// Type: int + /// Returns one of the following values. + /// + /// + /// Return code + /// Description + /// + /// + /// DRIVE_UNKNOWN + /// The drive type cannot be determined. + /// + /// + /// DRIVE_NO_ROOT_DIR + /// The root path is invalid. For example, no volume is mounted at the path. + /// + /// + /// DRIVE_REMOVABLE + /// The disk can be removed from the drive. + /// + /// + /// DRIVE_FIXED + /// The disk cannot be removed from the drive. + /// + /// + /// DRIVE_REMOTE + /// The drive is a remote (network) drive. + /// + /// + /// DRIVE_CDROM + /// The drive is a CD-ROM drive. + /// + /// + /// DRIVE_RAMDISK + /// The drive is a RAM disk. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-realdrivetype + // int RealDriveType( int iDrive, BOOL fOKToHitNet ); + // public static extern int RealDriveType(int iDrive, [MarshalAs(UnmanagedType.Bool)] bool fOKToHitNet); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "c4e55b50-637a-446f-aa9c-7d8c71d8071c")] + public static extern DRIVE_TYPE RealDriveType(int iDrive, [MarshalAs(UnmanagedType.Bool)] bool fOKToHitNet); + + /// + /// + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable + /// in subsequent versions of Windows.] + /// + /// + /// Displays a dialog box that prompts the user to restart Windows. When the user clicks the button, the function calls ExitWindowsEx + /// to attempt to restart Windows. + /// + /// + /// + /// TBD + /// + /// + /// Type: PCWSTR + /// A null-terminated Unicode string that contains the text that displays in the dialog box which prompts the user. + /// + /// + /// TBD + /// + /// + /// Type: int + /// Returns the identifier of the button that was pressed to close the dialog box. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-restartdialog + // int RestartDialog( HWND hwnd, PCWSTR pszPrompt, DWORD dwReturn ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "ec1e3c11-9960-482c-8461-72c4d41dff3c")] + public static extern int RestartDialog(HandleRef hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszPrompt, uint dwReturn); + + /// + /// + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable + /// in subsequent versions of Windows.] + /// + /// + /// Displays a dialog box that asks the user to restart Windows. When the user clicks the button, the function calls ExitWindowsEx to + /// attempt to restart Windows. + /// + /// + /// + /// TBD + /// + /// + /// Type: PCWSTR + /// A null-terminated string that contains the text that displays in the dialog box to prompt the user. + /// + /// + /// TBD + /// + /// + /// Type: DWORD + /// + /// Windows XP: Specifies the reason for initiating the shutdown. For more information, see System Shutdown Reason Codes. + /// + /// Windows 2000: This parameter is ignored. + /// + /// + /// Type: int + /// Returns the identifier of the button that was pressed to close the dialog box. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-restartdialogex + // int RestartDialogEx( HWND hwnd, PCWSTR pszPrompt, DWORD dwReturn, DWORD dwReasonCode ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "32bc232f-6cc4-4f19-9d33-ba7ad28dfd59")] + public static extern int RestartDialogEx(HandleRef hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszPrompt, uint dwReturn, uint dwReasonCode); + /// /// Notifies the system that an item has been accessed, for the purposes of tracking those items used most recently and most frequently. This function /// can also be used to clear all usage data. @@ -501,6 +1457,153 @@ namespace Vanara.PInvoke [PInvokeData("Shlobj.h", MSDNShortId = "bb762105")] public static extern void SHAddToRecentDocs(SHARD uFlags, PIDL pv); + /// + /// + /// Given a Shell namespace item specified in the form of a folder, and an item identifier list relative to that folder, this + /// function binds to the parent of the namespace item and optionally returns a pointer to the final component of the item identifier list. + /// + /// + /// + /// Type: IShellFolder* + /// A pointer to a Shell folder object. If is NULL, indicates that the IDList passed is relative to the desktop. + /// + /// + /// Type: PCUIDLIST_RELATIVE + /// A PIDL to bind to, relative to . If is NULL, this is an absolute IDList relative to the desktop folder. + /// + /// + /// Type: REFIID + /// + /// Reference to the desired interface ID. This is typically IID_IShellFolder or IID_IShellFolder2, but can be anything supported by + /// the target folder. + /// + /// + /// + /// Type: void** + /// + /// When this function returns, contains the interface pointer requested in . This is typically IShellFolder or IShellFolder2, but + /// can be anything supported by the target folder. + /// + /// + /// + /// Type: PCUITEMID_CHILD* + /// + /// A pointer to the last ID of the parameter, and is a child ID relative to the parent folder returned in . This value can be NULL. + /// + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// Note Calling the SHBindToFolderIDListParent function is equivalent to calling the SHBindToFolderIDListParentEx + /// function with NULL as the bind context. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shbindtofolderidlistparent + // SHSTDAPI SHBindToFolderIDListParent( IShellFolder *psfRoot, PCUIDLIST_RELATIVE pidl, REFIID riid, void **ppv, PCUITEMID_CHILD *ppidlLast ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "72a79d1b-15ed-475e-9ebd-03345579a06a")] + public static extern HRESULT SHBindToFolderIDListParent(IShellFolder psfRoot, PIDL pidl, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv, IntPtr ppidlLast); + + /// + /// Extends the SHBindToFolderIDListParent function by allowing the caller to specify a bind context. + /// + /// + /// Type: IShellFolder* + /// A pointer to a Shell folder object. If is NULL, indicates that the IDList passed is relative to the desktop. + /// + /// + /// Type: PCUIDLIST_RELATIVE + /// A PIDL to bind to, relative to . If is NULL, this is an absolute IDList relative to the desktop folder. + /// + /// + /// Type: IBindCtx* + /// + /// A pointer to IBindCtx interface on a bind context object to be used during this operation. If this parameter is not used, set it + /// to NULL, which is equivalent to calling the SHBindToFolderIDListParent function. Because support for is optional for + /// folder object implementations, some folders may not support the use of bind contexts. + /// + /// + /// + /// Type: REFIID + /// + /// Reference to the desired interface ID. This is typically IID_IShellFolder or IID_IShellFolder2, but can be anything supported by + /// the target folder. + /// + /// + /// + /// Type: void** + /// + /// When this function returns, contains the interface pointer requested in . This is typically IShellFolder or IShellFolder2, but + /// can be anything supported by the target folder. + /// + /// + /// + /// Type: PCUITEMID_CHILD* + /// + /// A pointer to the last ID of the parameter, and is a child ID relative to the parent folder returned in . This value can be NULL. + /// + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shbindtofolderidlistparentex + // SHSTDAPI SHBindToFolderIDListParentEx( IShellFolder *psfRoot, PCUIDLIST_RELATIVE pidl, IBindCtx *ppbc, REFIID riid, void **ppv, PCUITEMID_CHILD *ppidlLast ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "4f9b68cb-d0ae-45f7-90f5-2db1da3ab599")] + public static extern HRESULT SHBindToFolderIDListParentEx(IShellFolder psfRoot, PIDL pidl, IBindCtx ppbc, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv, IntPtr ppidlLast); + + /// + /// Retrieves and binds to a specified object by using the Shell namespace IShellFolder::BindToObject method. + /// + /// + /// Type: IShellFolder* + /// + /// A pointer to IShellFolder. This parameter can be NULL. If is NULL, this indicates parameter is relative to the + /// desktop. In this case, must specify an absolute ITEMIDLIST. + /// + /// + /// + /// Type: PCUIDLIST_RELATIVE + /// + /// A pointer to a constant ITEMIDLIST to bind to that is relative to . If is NULL, this is an absolute ITEMIDLIST + /// relative to the desktop folder. + /// + /// + /// + /// Type: IBindCtx* + /// + /// A pointer to IBindCtx interface on a bind context object to be used during this operation. If this parameter is not used, set it + /// to NULL. Because support for is optional for folder object implementations, some folders may not support the use of bind contexts. + /// + /// + /// + /// Type: REFIID + /// Identifier of the interface to return. + /// + /// + /// Type: void** + /// + /// When this method returns, contains the interface pointer as specified in to the bound object. If an error occurs, contains a + /// NULL pointer. + /// + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// Note This is a helper function that gets the desktop object by calling SHGetDesktopFolder. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shbindtoobject + // SHSTDAPI SHBindToObject( IShellFolder *psf, PCUIDLIST_RELATIVE pidl, IBindCtx *pbc, REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "acc16097-8301-4118-8cb5-00aa2705306a")] + public static extern HRESULT SHBindToObject(IShellFolder psf, PIDL pidl, IBindCtx pbc, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv); + /// Displays a dialog box that enables the user to select a Shell folder. /// A pointer to a BROWSEINFO structure that contains information used to display the dialog box. /// @@ -511,6 +1614,58 @@ namespace Vanara.PInvoke [PInvokeData("Shlobj.h", MSDNShortId = "bb762115")] public static extern PIDL SHBrowseForFolder(ref BROWSEINFO lpbi); + /// + /// Locks the shared memory associated with a Shell change notification event. + /// + /// + /// Type: HANDLE + /// A handle to a window received as a in the specified Shell change notification message. + /// + /// + /// Type: DWORD + /// The process ID ( in the message callback). + /// + /// + /// Type: PIDLIST_ABSOLUTE** + /// + /// The address of a pointer to a PIDLIST_ABSOLUTE that, when this function returns successfully, receives the list of affected PIDLs. + /// + /// + /// + /// Type: LONG* + /// + /// A pointer to a LONG value that, when this function returns successfully, receives the Shell change notification ID of the event + /// that took place. + /// + /// + /// + /// Type: HANDLE + /// Returns a handle (HLOCK) to the locked memory. Pass this value to SHChangeNotification_Unlock when finished. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shchangenotification_lock + // HANDLE SHChangeNotification_Lock( HANDLE hChange, DWORD dwProcId, PIDLIST_ABSOLUTE **pppidl, LONG *plEvent ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "8e22d5d0-64be-403c-982d-c23705d85223")] + public static extern IntPtr SHChangeNotification_Lock(IntPtr hChange, uint dwProcId, IntPtr pppidl, ref int plEvent); + + /// + /// Unlocks shared memory for a change notification. + /// + /// + /// Type: HANDLE + /// A handle to the memory lock. This is the handle returned by SHChangeNotification_Lock when it locked the memory. + /// + /// + /// Type: BOOL + /// Returns TRUE on success; otherwise, FALSE. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shchangenotification_unlock + // BOOL SHChangeNotification_Unlock( HANDLE hLock ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "967ede1f-ee9c-46ee-a371-dcfc3a57d824")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SHChangeNotification_Unlock(IntPtr hLock); + /// /// Notifies the system of an event that an application has performed. An application should use this function if it performs an /// action that may affect the Shell. @@ -526,6 +1681,339 @@ namespace Vanara.PInvoke [PInvokeData("Shlobj.h")] public static extern void SHChangeNotify(SHCNE wEventId, SHCNF uFlags, [Optional] IntPtr dwItem1, [Optional] IntPtr dwItem2); + /// + /// Unregisters the client's window process from receiving SHChangeNotify messages. + /// + /// + /// Type: ULONG + /// A value of type ULONG that specifies the registration ID returned by SHChangeNotifyRegister. + /// + /// + /// Type: BOOL + /// Returns TRUE if the specified client was found and removed; otherwise FALSE. + /// + /// + /// + /// See the Change Notify Watcher Sample in the Windows Software Development Kit (SDK) for a full example that demonstrates the use + /// of this function. + /// + /// + /// The NTSHChangeNotifyDeregister function, which is no longer available for use as of Windows Vista, was equivalent to SHChangeNotifyDeregister. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shchangenotifyderegister + // BOOL SHChangeNotifyDeregister( ULONG ulID ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shlobj_core.h", MSDNShortId = "fad021dc-8199-4384-b623-c98bc618799f")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SHChangeNotifyDeregister(uint ulID); + + /// + /// Enables asynchronous register and deregister of a thread. + /// + /// + /// Type: SCNRT_STATUS + /// Indicates whether the function is being used to register or deregister the thread. One of the values of SCNRT_STATUS. + /// + /// + /// This function does not return a value. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj/nf-shlobj-shchangenotifyregisterthread + // void SHChangeNotifyRegisterThread( SCNRT_STATUS status ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj.h", MSDNShortId = "170afefc-b4de-4661-9c12-1341656b0fdb")] + public static extern void SHChangeNotifyRegisterThread(SCNRT_STATUS status); + + /// + /// Creates a data object in a parent folder. + /// + /// + /// Type: PCIDLIST_ABSOLUTE + /// A pointer to an ITEMIDLIST (PIDL) of the parent folder that contains the data object. + /// + /// + /// Type: UINT + /// The number of file objects or subfolders specified in the parameter. + /// + /// + /// Type: PCUITEMID_CHILD_ARRAY + /// + /// An array of pointers to constant ITEMIDLIST structures, each of which uniquely identifies a file object or subfolder relative to + /// the parent folder. Each item identifier list must contain exactly one SHITEMID structure followed by a terminating zero. + /// + /// + /// + /// Type: IDataObject* + /// + /// A pointer to interface IDataObject. This parameter can be NULL. Specify only if the data object created needs to support + /// additional FORMATETC clipboard formats beyond the default formats it is assigned at creation. Alternatively, provide support for + /// populating the created data object using non-default clipboard formats by calling method IDataObject::SetData and specifying the + /// format in the FORMATETC structure passed in parameter . + /// + /// + /// + /// Type: REFIID + /// A reference to the IID of the interface to retrieve through . This must be IID_IDataObject. + /// + /// + /// Type: void** + /// When this method returns successfully, contains the IDataObject interface pointer requested in . + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// This function is typically called when implementing method IShellFolder::GetUIObjectOf. When an interface pointer of interface ID + /// IID_IDataObject is requested (using parameter ), the implementer can return the interface pointer on the object created with + /// SHCreateDataObject in response. + /// + /// + /// This function supports the CFSTR_SHELLIDLIST (also known as HIDA) clipboard format and also has generic support for arbitrary + /// clipboard formats through IDataObject::SetData. For more information on clipboard formats, see Shell Clipboard Formats. + /// + /// + /// The new data object is intended to be used in operations such as drag-and-drop, in which the data is stored in the clipboard with + /// a given format. + /// + /// + /// We recommend that you use the IID_PPV_ARGS macro, defined in Objbase.h, to package the and parameters. This macro provides the + /// correct IID based on the interface pointed to by the value in , which eliminates the possibility of a coding error in that could + /// lead to unexpected results. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shcreatedataobject + // SHSTDAPI SHCreateDataObject( PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "d56cdafe-9463-43a5-8ef0-6cfaf0c524a8")] + public static extern HRESULT SHCreateDataObject(PIDL pidlFolder, uint cidl, [In, MarshalAs(UnmanagedType.LPArray)] PIDL[] apidl, IDataObject pdtInner, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IDataObject ppv); + + /// + /// Creates an object that represents the Shell's default context menu implementation. + /// + /// + /// Type: const DEFCONTEXTMENU* + /// A pointer to a constant DEFCONTEXTMENU structure. + /// + /// + /// Type: REFIID + /// + /// Reference to the interface ID of the interface on which to base the object. This is typically the IID of IContextMenu, + /// IContextMenu2, or IContextMenu3. + /// + /// + /// + /// Type: void** + /// When this method returns, contains the interface pointer requested in riid. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + /// + /// + /// This function is typically used in the implementation of IShellFolder::GetUIObjectOf. GetUIObjectOf creates a context menu + /// that merges IContextMenu handlers specified by the DEFCONTEXTMENU structure, and can optionally provide default context menu verb + /// implementations such as open, explore, delete, and copy. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shcreatedefaultcontextmenu + // SHSTDAPI SHCreateDefaultContextMenu( const DEFCONTEXTMENU *pdcm, REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "055ff0a0-9ba7-463d-9684-3fd072b190da")] + public static extern HRESULT SHCreateDefaultContextMenu(ref DEFCONTEXTMENU pdcm, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv); + + /// + /// + /// [SHCreateDirectory is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions.] + /// + /// Creates a new file system folder. + /// + /// + /// Type: HWND + /// A handle to a parent window. This parameter can be set to NULL if no user interface is displayed. + /// + /// + /// Type: PCWSTR + /// + /// A pointer to a null-terminated Unicode string that contains the fully qualified path of the directory. This string should have no + /// more than MAX_PATH characters, including the terminating null character. + /// + /// + /// + /// Type: int + /// + /// Returns ERROR_SUCCESS if successful. If the operation fails, other error codes can be returned, including those listed + /// here. For values not specifically listed, see System Error Codes. + /// + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BAD_PATHNAME + /// The parameter was set to a relative path. + /// + /// + /// ERROR_FILENAME_EXCED_RANGE + /// The path pointed to by is too long. + /// + /// + /// ERROR_FILE_EXISTS + /// The directory exists. + /// + /// + /// ERROR_ALREADY_EXISTS + /// The directory exists. + /// + /// + /// ERROR_CANCELLED + /// The user canceled the operation. + /// + /// + /// + /// + /// + /// This function creates a file system folder whose fully qualified path is given by . If one or more of the intermediate folders do + /// not exist, it creates them. + /// + /// To set security attributes on a new folder, use SHCreateDirectoryEx. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shcreatedirectory + // int SHCreateDirectory( HWND hwnd, PCWSTR pszPath ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "4927429c-f457-4dda-aa0d-236eb236795c")] + public static extern Win32Error SHCreateDirectory([Optional] HandleRef hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszPath); + + /// + /// + /// [This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable + /// in subsequent versions of Windows.] + /// + /// Creates a new file system folder, with optional security attributes. + /// + /// + /// Type: HWND + /// A handle to a parent window. This parameter can be set to NULL if no user interface will be displayed. + /// + /// + /// Type: LPCTSTR + /// + /// A pointer to a null-terminated string specifying the fully qualified path of the directory. This string is of maximum length of + /// 248 characters, including the terminating null character. + /// + /// + /// + /// Type: const SECURITY_ATTRIBUTES* + /// + /// A pointer to a SECURITY_ATTRIBUTES structure with the directory's security attribute. Set this parameter to NULL if no + /// security attributes need to be set. + /// + /// + /// + /// Type: int + /// + /// Returns ERROR_SUCCESS if successful. If the operation fails, other error codes can be returned, including those listed + /// here. For values not specifically listed, see System Error Codes. + /// + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BAD_PATHNAME + /// The parameter was set to a relative path. + /// + /// + /// ERROR_FILENAME_EXCED_RANGE + /// The path pointed to by is too long. + /// + /// + /// ERROR_PATH_NOT_FOUND + /// The system cannot find the path pointed to by . The path may contain an invalid entry. + /// + /// + /// ERROR_FILE_EXISTS + /// The directory exists. + /// + /// + /// ERROR_ALREADY_EXISTS + /// The directory exists. + /// + /// + /// ERROR_CANCELLED + /// The user canceled the operation. + /// + /// + /// + /// + /// + /// This function creates a file system folder whose fully qualified path is given by . If one or more of the intermediate folders do + /// not exist, they are created as well. SHCreateDirectoryEx also verifies that the files are visible. If they are not + /// visible, expect one of the following: + /// + /// + /// + /// If is set to a valid window handle, a message box is displayed warning the user that he or she might not be able to access the + /// files. If the user chooses not to proceed, the function returns ERROR_CANCELLED. + /// + /// If is set to NULL, no user interface is displayed and the function returns ERROR_CANCELLED. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shcreatedirectoryexa + // int SHCreateDirectoryEx( HWND hwnd, LPCTSTR pszPath, const SECURITY_ATTRIBUTES *psa ); + [DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("shlobj_core.h", MSDNShortId = "7f44f907-cd12-4156-91c0-76e577ae25f6")] + public static extern Win32Error SHCreateDirectoryEx([Optional] HandleRef hwnd, string pszPath, [In] SECURITY_ATTRIBUTES psa); + + /// + /// [ + /// SHCreateFileExtractIcon + /// + /// is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in + /// subsequent versions.] + /// + /// + /// Creates a default IExtractIcon handler for a file system object. Namespace extensions that display file system objects typically + /// use this function. The extension and file attributes derive all that is needed for a simple icon extractor. + /// + /// + /// + /// Type: LPCTSTR + /// + /// A pointer to a null-terminated string that specifies the file system object. The buffer must not exceed MAX_PATH characters in length. + /// + /// + /// + /// Type: DWORD + /// + /// A combination of one or more file attribute flags (FILE_ATTRIBUTE_* values as defined in Winnt.h) that specify the type of object. + /// + /// + /// + /// Type: REFIID + /// + /// Reference to the desired interface ID of the icon extractor interface to create. This must be either IID_IExtractIconA or IID_IExtractIconW. + /// + /// + /// + /// Type: void** + /// When this function returns, contains the interface pointer requested in . This is typically IExtractIcon. + /// + /// + /// Type: HRESULT + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shcreatefileextracticonw + // SHSTDAPI SHCreateFileExtractIconW( LPCWSTR pszFile, DWORD dwFileAttributes, REFIID riid, void **ppv ); + [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("shlobj_core.h", MSDNShortId = "af3beb0a-892b-43e5-b5b8-8005f497b6e5")] + public static extern HRESULT SHCreateFileExtractIconW([MarshalAs(UnmanagedType.LPWStr)] string pszFile, FileFlagsAndAttributes dwFileAttributes, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv); + /// Creates a new instance of the default Shell folder view object (DefView). /// Pointer to a SFV_CREATE structure that describes the particulars used in creating this instance of the Shell folder view object. /// When this function returns successfully, contains an interface pointer to the new IShellView object. On failure, this value is NULL. @@ -933,6 +2421,50 @@ namespace Vanara.PInvoke public static extern HRESULT SHParseDisplayName([MarshalAs(UnmanagedType.LPWStr)] string pszName, [In, Optional] IntPtr pbc, out PIDL ppidl, SFGAO sfgaoIn, out SFGAO psfgaoOut); + /// + /// + /// [CABINETSTATE is available for use in the operating systems specified in the Requirements section. It may be altered or + /// unavailable in subsequent versions.] + /// + /// + /// Holds the global configuration for Windows Explorer and Windows Internet Explorer. This structure is used in the ReadCabinetState + /// and WriteCabinetState functions. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/ns-shlobj_core-cabinetstate + // typedef struct CABINETSTATE { WORD cLength; WORD nVersion; BOOL fFullPathTitle : 1; BOOL fSaveLocalView : 1; BOOL fNotShell : 1; BOOL fSimpleDefault : 1; BOOL fDontShowDescBar : 1; BOOL fNewWindowMode : 1; BOOL fShowCompColor : 1; BOOL fDontPrettyNames : 1; BOOL fAdminsCreateCommonGroups : 1; UINT fUnusedFlags : 7; UINT fMenuEnumFilter; } *LPCABINETSTATE; + [PInvokeData("shlobj_core.h", MSDNShortId = "4b82b6a8-c4c0-4af2-9612-0551376c1c62")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct CABINETSTATE + { + /// Type: WORDThe size of the structure, in bytes. + public ushort cLength; + /// Type: WORD + public ushort nVersion; + private ushort fFlags; + /// Type: UINTOne or both of the following flags.SHCONTF_FOLDERSDisplay folders.SHCONTF_NONFOLDERSDisplay non-folder items. + public SHCONTF fMenuEnumFilter; + + /// Type: BOOLTRUEDisplay the full path in the title bar.FALSEDisplay only the file name in the title bar. + public bool fFullPathTitle { get => (fFlags & 1 << 0) != 0; set { if (value) fFlags |= 1 << 0; else { int i = fFlags; i &= ~(1 << 0); fFlags = (ushort)i; } } } + /// Type: BOOLTRUERemember each folder's view settings.FALSEUse global settings for all folders. + public bool fSaveLocalView { get => (fFlags & 1 << 1) != 0; set { if (value) fFlags |= 1 << 1; else { int i = fFlags; i &= ~(1 << 1); fFlags = (ushort)i; } } } + /// Type: BOOLNot used. + public bool fNotShell { get => (fFlags & 1 << 2) != 0; set { if (value) fFlags |= 1 << 2; else { int i = fFlags; i &= ~(1 << 2); fFlags = (ushort)i; } } } + /// Type: BOOLNot used. + public bool fSimpleDefault { get => (fFlags & 1 << 3) != 0; set { if (value) fFlags |= 1 << 3; else { int i = fFlags; i &= ~(1 << 3); fFlags = (ushort)i; } } } + /// Type: BOOLNot used. + public bool fDontShowDescBar { get => (fFlags & 1 << 4) != 0; set { if (value) fFlags |= 1 << 4; else { int i = fFlags; i &= ~(1 << 4); fFlags = (ushort)i; } } } + /// Type: BOOLTRUEDisplay in a new window.FALSEDisplay in the current window. + public bool fNewWindowMode { get => (fFlags & 1 << 5) != 0; set { if (value) fFlags |= 1 << 5; else { int i = fFlags; i &= ~(1 << 5); fFlags = (ushort)i; } } } + /// Type: BOOLTRUEShow encrypted or compressed NTFS files in color.FALSEDo not show encrypted or compressed NTFS files in color. + public bool fShowCompColor { get => (fFlags & 1 << 6) != 0; set { if (value) fFlags |= 1 << 6; else { int i = fFlags; i &= ~(1 << 6); fFlags = (ushort)i; } } } + /// Type: BOOLNot used. + public bool fDontPrettyNames { get => (fFlags & 1 << 7) != 0; set { if (value) fFlags |= 1 << 7; else { int i = fFlags; i &= ~(1 << 7); fFlags = (ushort)i; } } } + /// Type: BOOLUsed when an administrator installs an application that places an icon in the Start menu.TRUEAdd the icon to the Start menu for all users (CSIDL_COMMON_STARTMENU). This is the default value.FALSEAdd the icon to only the current user (CSIDL_STARTMENU). + public bool fAdminsCreateCommonGroups { get => (fFlags & 1 << 8) != 0; set { if (value) fFlags |= 1 << 8; else { int i = fFlags; i &= ~(1 << 8); fFlags = (ushort)i; } } } + } + /// /// Defines the coordinates of a character cell in a console screen buffer. The origin of the coordinate system (0,0) is at the top, left cell of the buffer. /// @@ -959,6 +2491,65 @@ namespace Vanara.PInvoke public ShellDataBlockSignature dwSignature; } + /// Contains context menu information used by SHCreateDefaultContextMenu. + [StructLayout(LayoutKind.Sequential)] + [PInvokeData("shlobj_core.h")] + public struct DEFCONTEXTMENU + { + /// A handle to the context menu. Set this member to the handle returned from CreateMenu. + public IntPtr hwnd; + + /// + /// A pointer to the IContextMenuCB interface supported by the callback object. This value is optional and can be NULL. + /// + public IContextMenuCB pcmcb; + + /// + /// The PIDL of the folder that contains the selected file object(s) or the folder of the context menu if no file objects are + /// selected. This value is optional and can be NULL, in which case the PIDL is computed from the psf member. + /// + public IntPtr pidlFolder; + + /// + /// A pointer to the IShellFolder interface of the folder object that contains the selected file objects, or the folder that + /// contains the context menu if no file objects are selected. + /// + public IShellFolder psf; + + /// The count of items in member apidl. + public uint cidl; + + /// + /// A pointer to a constant array of ITEMIDLIST structures. Each entry in the array describes a child item to which the context + /// menu applies, for instance, a selected file the user wants to Open. + /// + public IntPtr apidl; + + /// + /// A pointer to the IQueryAssociations interface on the object from which to load extensions. This parameter is optional and + /// thus can be NULL. If this value is NULL and members aKeys and cKeys are also NULL (see Remarks), punkAssociationInfo is + /// computed from the apidl member and cidl via a request for IQueryAssociations through IShellFolder::GetUIObjectOf. If + /// IShellFolder::GetUIObjectOf returns E_NOTIMPL, a default implementation is provided based on the SFGAO_FOLDER and + /// SFGAO_FILESYSTEM attributes returned from IShellFolder::GetAttributesOf. + /// + public IQueryAssociations punkAssociationInfo; + + /// The count of items in member aKeys. This value can be zero. If the value is zero, the extensions are loaded based + /// on the object that supports interface IQueryAssociations as specified by member punkAssociationInfo. If the value is + /// non-NULL, the extensions are loaded based only on member aKeys and not member punkAssociationInfo. + // Note The maximum number of keys is 16. Callers must enforce this limit as the API does not. Failing to do so can result in + // memory corruption. + /// + public uint cKeys; + + /// + /// A pointer to an HKEY that specifies the registry key from which to load extensions. This parameter is optional and can be + /// NULL. If the value is NULL, the extensions are loaded based on the object that supports interface IQueryAssociations as + /// specified in punkAssociationInfo. + /// + public IntPtr aKeys; + } + /// Holds an extra data block used by IShellLinkDataList. It holds the link's Windows Installer ID. [StructLayout(LayoutKind.Sequential, Pack = 4)] [PInvokeData("Shlobj.h", MSDNShortId = "bb773274")] @@ -1106,6 +2697,53 @@ namespace Vanara.PInvoke public uint uCodePage; } + /// This structure contains information from a .pif file. It is used by PifMgr_GetProperties. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/ns-shlobj_core-propprg + // typedef struct PROPPRG { WORD flPrg; WORD flPrgInit; CHAR achTitle[PIFNAMESIZE]; CHAR achCmdLine[PIFSTARTLOCSIZE + PIFPARAMSSIZE + 1]; CHAR achWorkDir[PIFDEFPATHSIZE]; WORD wHotKey; CHAR achIconFile[PIFDEFFILESIZE]; WORD wIconIndex; DWORD dwEnhModeFlags; DWORD dwRealModeFlags; CHAR achOtherFile[PIFDEFFILESIZE]; CHAR achPIFFile[PIFMAXFILEPATH]; }; + [PInvokeData("shlobj_core.h", MSDNShortId = "603f990b-efb8-4d72-bc96-27bda4ffcbd8")] + [StructLayout(LayoutKind.Sequential)] + public struct PROPPRG + { + private const int PIFNAMESIZE = 30; + private const int PIFSTARTLOCSIZE = 63; + private const int PIFDEFPATHSIZE = 64; + private const int PIFPARAMSSIZE = 64; + private const int PIFSHPROGSIZE = 64; + private const int PIFSHDATASIZE = 64; + private const int PIFDEFFILESIZE = 80; + private const int PIFMAXFILEPATH = 260; + + /// Type: WORDFlags that describe how the program will run.PRG_DEFAULTUse the default options.PRG_CLOSEONEXITClose the application on exit. + public ushort flPrg; + /// Type: WORDFlags that specify the initial conditions for the application.PRGINIT_DEFAULTUse the default options.PRGINIT_MINIMIZEDThe application should be minimized.PRGINIT_MAXIMIZEDThe application should be maximized.PRGINIT_REALMODEThe application should run in real mode.PRGINIT_REALMODESILENTThe application should run in real mode without being prompted.PRGINIT_AMBIGUOUSPIFThe data is ambiguous.PRGINIT_NOPIFNo .pif file was found.PRGINIT_DEFAULTPIFA default .pif was found.PRGINIT_INFSETTINGSA .inf file was found.PRGINIT_INHIBITPIFThe .inf file indicates that a .pif file should not be created. + public ushort flPrgInit; + /// Type: __wchar_tA null-terminated string that contains the title. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PIFNAMESIZE)] + public byte[] achTitle; + /// Type: __wchar_tA null-terminated string that contains the command line, including arguments. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PIFSTARTLOCSIZE + PIFPARAMSSIZE + 1)] + public byte[] achCmdLine; + /// Type: __wchar_tA null-terminated string that contains the working directory. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PIFDEFPATHSIZE)] + public byte[] achWorkDir; + /// Type: WORDThe key code of the .pif file's hotkey. + public ushort wHotKey; + /// Type: __wchar_tA null-terminated string that contains the name of the file that contains the icon. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PIFDEFFILESIZE)] + public byte[] achIconFile; + /// Type: WORDThe index of the icon in the file specified by achIconFile. + public ushort wIconIndex; + /// Type: DWORDReserved. + public uint dwEnhModeFlags; + /// Type: DWORDFlags that specify the real mode options.RMOPT_MOUSERequires a real-mode mouse.RMOPT_EMSRequires expanded memory.RMOPT_CDROMRequires CD-ROM support.RMOPT_NETWORKRequires network support.RMOPT_DISKLOCKRequires disk locking.RMOPT_PRIVATECFGUse a private config.sys or autoexec.bat file.RMOPT_VESARequires a VESA driver. + public uint dwRealModeFlags; + /// Type: __wchar_tA null-terminated string that contains the name of the "other" file in the directory. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PIFDEFFILESIZE)] + public byte[] achOtherFile; + /// Type: __wchar_tA null-terminated string that contains the name of the .pif file in the directory. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PIFMAXFILEPATH)] + public byte[] achPIFFile; + } /// This structure is used with the SHCreateShellFolderView function. [StructLayout(LayoutKind.Sequential)] [PInvokeData("Shlobj.h")] diff --git a/PInvoke/Shell32/Vanara.PInvoke.Shell32.csproj b/PInvoke/Shell32/Vanara.PInvoke.Shell32.csproj index a471e5b9..7efc9ec2 100644 --- a/PInvoke/Shell32/Vanara.PInvoke.Shell32.csproj +++ b/PInvoke/Shell32/Vanara.PInvoke.Shell32.csproj @@ -58,5 +58,6 @@ IAutoComplete, IAutoComplete2, IExtractIcon, IOpenControlPanel, IApplicationDest + \ No newline at end of file diff --git a/PInvoke/ShlwApi/Shlwapi.cs b/PInvoke/ShlwApi/Shlwapi.cs index a1246db3..ea2e3b64 100644 --- a/PInvoke/ShlwApi/Shlwapi.cs +++ b/PInvoke/ShlwApi/Shlwapi.cs @@ -1,3 +1,4 @@ +using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; @@ -40,5 +41,209 @@ namespace Vanara.PInvoke [PInvokeData("Shlwapi.h", MSDNShortId = "bb759866")] public static extern HRESULT SHCreateStreamOnFileEx(string pszFile, STGM grfMode, FileFlagsAndAttributes dwAttributes, [MarshalAs(UnmanagedType.Bool)] bool fCreate, [Optional] IStream pstmTemplate, out IStream ppstm); + + /// + /// Exposes methods that simplify the process of retrieving information stored in the registry in association with defining a file + /// type or protocol and associating it with an application. + /// + // https://msdn.microsoft.com/en-us/library/windows/desktop/bb761400(v=vs.85).aspx + [PInvokeData("Shlwapi.h", MSDNShortId = "bb761400")] + [ComImport, Guid("c46ca590-3c3f-11d2-bee6-0000f805ca57"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IQueryAssociations + { + /// + /// Initializes the IQueryAssociations interface and sets the root key to the appropriate ProgID. + /// + /// A flag that specifies how the search is to be initialized. It is typically set to zero, but it can also take one of the following ASSOCF values. + /// A Unicode string that is used to determine the root key. If a value is specified for hkProgid, set this parameter to NULL. Four types of string can be used: + /// + /// File name extensionA file name extension, such as .txt. + /// CLSIDA CLSID GUID in the standard "{GUID}" format. + /// ProgIDAn application's ProgID, such as Word.Document.8. + /// Executable nameThe name of an application's .exe file. The ASSOCF_OPEN_BYEXENAME flag must be set in flags. + /// + /// The HKEY value of the subkey that is used as a root key. The search looks only below this key. If a value is specified for pwszAssoc, set this parameter to NULL. + /// The HWND. + void Init(ASSOCF flags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszAssoc, [Optional] IntPtr hkProgid, [Optional] IntPtr hwnd); + /// + /// Searches for and retrieves a file or protocol association-related string from the registry. + /// + /// A flag that can be used to control the search. It can be any combination of the following ASSOCF values. + /// An ASSOCSTR value that specifies the type of string that is to be returned. + /// A pointer to an optional, null-terminated Unicode string with information about the location of the string. It is typically set to a Shell verb such as open. Set this parameter to NULL if it is not used. + /// A pointer to a null-terminated Unicode string used to return the requested string. Set this parameter to NULL to retrieve the required buffer size. + /// A pointer to a value that, on entry, is set to the number of characters in the pwszOut buffer. When the function returns successfully, it points to the number of characters placed in the buffer. + /// If the ASSOCF_NOTRUNCATE flag is set in flags and the buffer specified in pwszOut is too small, the function returns E_POINTER and pcchOut points to the required size of the buffer. + /// If pwszOut is NULL, the function returns S_FALSE and pcchOut points to the required size of the buffer. + void GetString(ASSOCF flags, ASSOCSTR str, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszExtra, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszOut, ref uint pcchOut); + /// + /// Searches for and retrieves a file or protocol association-related key from the registry. + /// + /// The ASSOCF value that can be used to control the search. + /// The ASSOCKEY value that specifies the type of key that is to be returned. + /// A pointer to an optional, null-terminated Unicode string with information about the location of the key. It is normally set to a Shell verb such as open. Set this parameter to NULL if it is not used. + /// A pointer to the key's HKEY value. + void GetKey(ASSOCF flags, ASSOCKEY key, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszExtra, out IntPtr phkeyOut); + /// + /// Searches for and retrieves file or protocol association-related binary data from the registry. + /// + /// The ASSOCF value that can be used to control the search. + /// The ASSOCDATA value that specifies the type of data that is to be returned. + /// A pointer to an optional, null-terminated Unicode string with information about the location of the data. It is normally set to a Shell verb such as open. Set this parameter to NULL if it is not used. + /// A pointer to a value that, when this method returns successfully, receives the requested data value. + /// A pointer to a value that, when this method is called, holds the size of pvOut, in bytes. When this method returns successfully, the value contains the size of the data actually retrieved. + void GetData(ASSOCF flags, ASSOCDATA data, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszExtra, IntPtr pvOut, ref uint pcbOut); + /// + /// This method is not implemented. + /// + /// Undocumented. + /// Undocumented. + /// Undocumented. + /// Undocumented. + /// Undocumented. + void GetEnum(ASSOCF flags, ASSOCENUM assocenum, [MarshalAs(UnmanagedType.LPWStr)] string pszExtra, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr ppvOut); + } + + /// Provides information to the IQueryAssociations interface methods. + // typedef enum { ASSOCF_NONE = 0x00000000, ASSOCF_INIT_NOREMAPCLSID = 0x00000001, ASSOCF_INIT_BYEXENAME = 0x00000002, ASSOCF_OPEN_BYEXENAME = 0x00000002, ASSOCF_INIT_DEFAULTTOSTAR = 0x00000004, ASSOCF_INIT_DEFAULTTOFOLDER = 0x00000008, ASSOCF_NOUSERSETTINGS = 0x00000010, ASSOCF_NOTRUNCATE = 0x00000020, ASSOCF_VERIFY = 0x00000040, ASSOCF_REMAPRUNDLL = 0x00000080, ASSOCF_NOFIXUPS = 0x00000100, ASSOCF_IGNOREBASECLASS = 0x00000200, ASSOCF_INIT_IGNOREUNKNOWN = 0x00000400, ASSOCF_INIT_FIXED_PROGID = 0x00000800, ASSOCF_IS_PROTOCOL = 0x00001000, ASSOCF_INIT_FOR_FILE = 0x00002000} ASSOCF; + // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762471(v=vs.85).aspx + [Flags] + [PInvokeData("Shlwapi.h", MSDNShortId = "bb762471")] + public enum ASSOCF + { + /// None of the following options are set. + ASSOCF_NONE = 0x00000000, + /// Instructs IQueryAssociations interface methods not to map CLSID values to ProgID values. + ASSOCF_INIT_NOREMAPCLSID = 0x00000001, + /// Identifies the value of the pwszAssoc parameter of IQueryAssociations::Init as an executable file name. If this flag is not set, the root key will be set to the ProgID associated with the .exe key instead of the executable file's ProgID. + ASSOCF_INIT_BYEXENAME = 0x00000002, + /// Identical to ASSOCF_INIT_BYEXENAME. + ASSOCF_OPEN_BYEXENAME = 0x00000002, + /// Specifies that when an IQueryAssociations method does not find the requested value under the root key, it should attempt to retrieve the comparable value from the * subkey. + ASSOCF_INIT_DEFAULTTOSTAR = 0x00000004, + /// Specifies that when a IQueryAssociations method does not find the requested value under the root key, it should attempt to retrieve the comparable value from the Folder subkey. + ASSOCF_INIT_DEFAULTTOFOLDER = 0x00000008, + /// Specifies that only HKEY_CLASSES_ROOT should be searched, and that HKEY_CURRENT_USER should be ignored. + ASSOCF_NOUSERSETTINGS = 0x00000010, + /// + /// Specifies that the return string should not be truncated. Instead, return an error value and the required size for the + /// complete string. + /// + ASSOCF_NOTRUNCATE = 0x00000020, + /// Specifies that the return string should not be truncated. Instead, return an error value and the required size for the complete string. + ASSOCF_VERIFY = 0x00000040, + /// Instructs IQueryAssociations methods to ignore Rundll.exe and return information about its target. Typically IQueryAssociations methods return information about the first .exe or .dll in a command string. If a command uses Rundll.exe, setting this flag tells the method to ignore Rundll.exe and return information about its target. + ASSOCF_REMAPRUNDLL = 0x00000080, + /// Instructs IQueryAssociations methods not to fix errors in the registry, such as the friendly name of a function not matching the one found in the .exe file. + ASSOCF_NOFIXUPS = 0x00000100, + /// Specifies that the BaseClass value should be ignored. + ASSOCF_IGNOREBASECLASS = 0x00000200, + /// Introduced in Windows 7. Specifies that the "Unknown" ProgID should be ignored; instead, fail. + ASSOCF_INIT_IGNOREUNKNOWN = 0x00000400, + /// Introduced in Windows 8. Specifies that the supplied ProgID should be mapped using the system defaults, rather than the current user defaults. + ASSOCF_INIT_FIXED_PROGID = 0x00000800, + /// Introduced in Windows 8. Specifies that the value is a protocol, and should be mapped using the current user defaults. + ASSOCF_IS_PROTOCOL = 0x00001000, + /// Introduced in Windows 8.1. Specifies that the ProgID corresponds with a file extension based association. Use together with ASSOCF_INIT_FIXED_PROGID. + ASSOCF_INIT_FOR_FILE = 0x00002000 + } + + /// Used by IQueryAssociations::GetString to define the type of string that is to be returned. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-assocstr + [PInvokeData("shlwapi.h", MSDNShortId = "b5fd3d25-3630-4dd8-acd2-d2e4ed571604")] + public enum ASSOCSTR + { + /// A command string associated with a Shell verb. + ASSOCSTR_COMMAND = 1, + /// An executable from a Shell verb command string. For example, this string is found as the (Default) value for a subkey such as HKEY_CLASSES_ROOT\\shell\Open\command. If the command uses Rundll.exe, set the ASSOCF_REMAPRUNDLL flag in the parameter of IQueryAssociations::GetString to retrieve the target executable. This type of string will identify the code that will be invoked in the implementation of the verb. + ASSOCSTR_EXECUTABLE, + /// The friendly name of a document type. + ASSOCSTR_FRIENDLYDOCNAME, + /// The friendly name of an executable file. + ASSOCSTR_FRIENDLYAPPNAME, + /// Ignore the information associated with the open subkey. + ASSOCSTR_NOOPEN, + /// Look under the ShellNew subkey. + ASSOCSTR_SHELLNEWVALUE, + /// The DDE command to use to create a process. + ASSOCSTR_DDEIFEXEC, + /// The application name in a DDE broadcast. + ASSOCSTR_DDEAPPLICATION, + /// The topic name in a DDE broadcast. + ASSOCSTR_DDETOPIC, + /// Corresponds to the InfoTip registry value. Returns an info tip for an item, or list of properties in the form of an IPropertyDescriptionList from which to create an info tip, such as when hovering the cursor over a file name. The list of properties can be parsed with PSGetPropertyDescriptionListFromString. + ASSOCSTR_INFOTIP, + /// Introduced in Internet Explorer 6. Corresponds to the QuickTip registry value. Same as ASSOCSTR_INFOTIP, except that it always returns a list of property names in the form of an IPropertyDescriptionList. The difference between this value and ASSOCSTR_INFOTIP is that this returns properties that are safe for any scenario that causes slow property retrieval, such as offline or slow networks. Some of the properties returned from ASSOCSTR_INFOTIP might not be appropriate for slow property retrieval scenarios. The list of properties can be parsed with PSGetPropertyDescriptionListFromString. + ASSOCSTR_QUICKTIP, + /// Introduced in Internet Explorer 6. Corresponds to the TileInfo registry value. Contains a list of properties to be displayed for a particular file type in a Windows Explorer window that is in tile view. This is the same as ASSOCSTR_INFOTIP, but, like ASSOCSTR_QUICKTIP, it also returns a list of property names in the form of an IPropertyDescriptionList. The list of properties can be parsed with PSGetPropertyDescriptionListFromString. + ASSOCSTR_TILEINFO, + /// Introduced in Internet Explorer 6. Describes a general type of MIME file association, such as image and bmp, so that applications can make general assumptions about a specific file type. + ASSOCSTR_CONTENTTYPE, + /// Introduced in Internet Explorer 6. Returns the path to the icon resources to use by default for this association. Positive numbers indicate an index into the dll's resource table, while negative numbers indicate a resource ID. An example of the syntax for the resource is "c:\myfolder\myfile.dll,-1". + ASSOCSTR_DEFAULTICON, + /// Introduced in Internet Explorer 6. For an object that has a Shell extension associated with it, you can use this to retrieve the CLSID of that Shell extension object by passing a string representation of the IID of the interface you want to retrieve as the parameter of IQueryAssociations::GetString. For example, if you want to retrieve a handler that implements the IExtractImage interface, you would specify "{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}", which is the IID of IExtractImage. + ASSOCSTR_SHELLEXTENSION, + /// Introduced in Internet Explorer 8.. For a verb invoked through COM and the IDropTarget interface, you can use this flag to retrieve the IDropTarget object's CLSID. This CLSID is registered in the DropTarget subkey. The verb is specified in the parameter in the call to IQueryAssociations::GetString. This type of string will identify the code that will be invoked in the implementation of the verb. + ASSOCSTR_DROPTARGET, + /// Introduced in Internet Explorer 8.. For a verb invoked through COM and the IExecuteCommand interface, you can use this flag to retrieve the IExecuteCommand object's CLSID. This CLSID is registered in the verb's command subkey as the DelegateExecute entry. The verb is specified in the parameter in the call to IQueryAssociations::GetString. This type of string will identify the code that will be invoked in the implementation of the verb. + ASSOCSTR_DELEGATEEXECUTE, + /// Introduced in Windows 8. + ASSOCSTR_SUPPORTED_URI_PROTOCOLS, + /// The ProgID provided by the app associated with the file type or URI scheme. This if configured by users in their default program settings. + ASSOCSTR_PROGID, + /// The AppUserModelID of the app associated with the file type or URI scheme. This is configured by users in their default program settings. + ASSOCSTR_APPID, + /// The publisher of the app associated with the file type or URI scheme. This is configured by users in their default program settings. + ASSOCSTR_APPPUBLISHER, + /// The icon reference of the app associated with the file type or URI scheme. This is configured by users in their default program settings. + ASSOCSTR_APPICONREFERENCE, + /// The maximum defined ASSOCSTR value, used for validation purposes. + ASSOCSTR_MAX, + } + + /// Specifies the type of key to be returned by IQueryAssociations::GetKey. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-assockey + [PInvokeData("shlwapi.h", MSDNShortId = "f4ac0ba0-4113-498f-a51b-74a37fe33d49")] + public enum ASSOCKEY + { + /// A key that is passed to ShellExecuteEx through a SHELLEXECUTEINFO structure. + ASSOCKEY_SHELLEXECCLASS = 1, + /// An Application key for the file type. + ASSOCKEY_APP, + /// A ProgID or class key. + ASSOCKEY_CLASS, + /// A BaseClass value. + ASSOCKEY_BASECLASS, + /// + ASSOCKEY_MAX, + } + + /// Used by IQueryAssociations::GetData to define the type of data that is to be returned. + // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-assocdata + [PInvokeData("shlwapi.h", MSDNShortId = "0ae5c8db-81fd-4d00-8e54-0c474f1bfd06")] + public enum ASSOCDATA + { + /// The component descriptor to pass to the Windows Installer API. + ASSOCDATA_MSIDESCRIPTOR = 1, + /// Attempts to activate a window are restricted. There is no data associated with this value. + ASSOCDATA_NOACTIVATEHANDLER, + /// + ASSOCDATA_UNUSED1, + /// Defaults to user specified association. + ASSOCDATA_HASPERUSERASSOC, + /// Internet Explorer version 6 or later. Gets the data stored in the EditFlags value of a file association PROGID registry key. This value consists of one or more FILETYPEATTRIBUTEFLAGS. Compare against those values to determine which attributes have been set. + ASSOCDATA_EDITFLAGS, + /// Internet Explorer version 6 or later. Uses the parameter from the IQueryAssociations::GetData method as the value name. + ASSOCDATA_VALUE, + /// + ASSOCDATA_MAX, + } + + /// Used by IQueryAssociations::GetEnum to define the type of enum that is to be returned. + public enum ASSOCENUM + { + /// Nothing. + ASSOCENUM_NONE + } } }