Added many more functions and interfaces from Shell32

pull/10/head
David Hall 2018-07-25 11:45:49 -06:00
parent d64d154c08
commit ba0a2313b6
6 changed files with 2967 additions and 17 deletions

View File

@ -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);
}
/// <summary>
/// Exposes a method that enables the callback of a context menu. For example, to add a shield icon to a menuItem that requires elevation.
/// </summary>
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("3409E930-5A39-11d1-83FA-00A0C90DC849")]
public interface IContextMenuCB
{
/// <summary>Enables the callback function for a context menu.</summary>
/// <param name="psf">
/// 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.
/// </param>
/// <param name="hwndOwner">A handle to the owner of the context menu. This value can be NULL.</param>
/// <param name="pdtobj">
/// A pointer to an IDataObject that contains information about a menu selection. Implement interface IDataObject, or call
/// SHCreateDataObject for the default implementation.
/// </param>
/// <param name="uMsg">
/// 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.
/// </param>
/// <param name="wParam">
/// Data specific to the notification specified in uMsg. See the individual notification page for specific requirements.
/// </param>
/// <param name="lParam">
/// Data specific to the notification specified in uMsg. See the individual notification page for specific requirements.
/// </param>
/// <returns>If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PreserveSig]
HRESULT CallBack(IShellFolder psf, IntPtr hwndOwner, IDataObject pdtobj, uint uMsg, IntPtr wParam, IntPtr lParam);
}
/*
/// <summary>Contains information needed by IContextMenu::InvokeCommand to invoke a shortcut menu command.</summary>
[StructLayout(LayoutKind.Sequential)]

View File

@ -27,12 +27,13 @@ namespace Vanara.PInvoke
/// <summary>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.
/// <para>Used with IShellFolder::BindToObject or IShellItem::BindToHandler.</para></summary>
public const string STR_BIND_DELEGATE_CREATE_OBJECT = "Delegate Object Creation";
/// <summary>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.</summary>
public const string STR_BIND_FOLDERS_READ_ONLY = "Folders As Read Only";
/// <summary>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.
/// <para>Items with different enumeration modes compare canonically(SHCIDS_CANONICALONLY) different because they enumerate different sets of items.</para>
/// <para>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.</para></summary>
public const string STR_BIND_FOLDER_ENUM_MODE = "Folder Enum Mode";
/// <summary>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.</summary>
public const string STR_BIND_FOLDERS_READ_ONLY = "Folders As Read Only";
/// <summary>Introduced in Windows XP SP2. Specify this bind context to force a folder shortcut to resolve the link that points to its target.
/// <para>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.</para>
/// <para>Used with IShellFolder::BindToObject or IShellItem::BindToHandler.</para></summary>
@ -100,6 +101,12 @@ namespace Vanara.PInvoke
public const string STR_PARSE_SKIP_NET_CACHE = "Skip Net Resource Cache";
/// <summary>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.</summary>
public const string STR_PARSE_TRANSLATE_ALIASES = "Parse Translate Aliases";
/// <summary>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.</summary>
public const string STR_PARSE_WITH_EXPLICIT_ASSOCAPP = "ExplicitAssociationApp";
/// <summary>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.</summary>
public const string STR_PARSE_WITH_EXPLICIT_PROGID = "ExplicitProgid";
/// <summary>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.
/// <para>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.</para>
/// <para>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:</para>
@ -112,22 +119,18 @@ namespace Vanara.PInvoke
/// <para>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.</para>
/// <para>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.</para></summary>
public const string STR_PARSE_WITH_PROPERTIES = "ParseWithProperties";
/// <summary>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.</summary>
public const string STR_PARSE_WITH_EXPLICIT_ASSOCAPP = "ExplicitAssociationApp";
/// <summary>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.</summary>
public const string STR_PARSE_WITH_EXPLICIT_PROGID = "ExplicitProgid";
/// <summary>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.</summary>
public const string STR_PROPERTYBAG_PARAM = "SHBindCtxPropertyBag";
/// <summary>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.</summary>
public const string STR_SKIP_BINDING_CLSID = "Skip Binding CLSID";
/// <summary>Not used.</summary>
public const string STR_TRACK_CLSID = "Track the CLSID";
/// <summary>The string referrer identifier</summary>
public const string STR_REFERRER_IDENTIFIER = "Referrer Identifier";
/// <summary>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.</summary>
public const string STR_SKIP_BINDING_CLSID = "Skip Binding CLSID";
/// <summary>The string tab reuse identifier</summary>
public const string STR_TAB_REUSE_IDENTIFIER = "Tab Reuse Identifier";
/// <summary>Not used.</summary>
public const string STR_TRACK_CLSID = "Track the CLSID";
/// <summary>Values that specify from which category the list of destinations should be retrieved.</summary>
[PInvokeData("Shobjidl.h", MSDNShortId = "dd378410")]
public enum APPDOCLISTTYPE
@ -139,6 +142,53 @@ namespace Vanara.PInvoke
FREQUENT
}
/// <summary>Specifies the enumeration handler filter applied to the full list of handlers in SHAssocEnumHandlers.</summary>
[PInvokeData("shobjidl_core.h", MSDNShortId = "83db466b-e00c-4015-879f-c5c222f45b8c")]
public enum ASSOC_FILTER
{
/// <summary>Return all handlers.</summary>
ASSOC_FILTER_NONE = 0x0,
/// <summary>
/// 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.
/// </summary>
ASSOC_FILTER_RECOMMENDED = 0x1,
}
/// <summary><para>Specifies the source of the default association for a file name extension. Used by methods of the IApplicationAssociationRegistration interface.</para></summary>
// 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
{
/// <summary>The machine-level default application association.</summary>
AL_MACHINE,
/// <summary>The effective default for the current user. This value should be used by most applications.</summary>
AL_EFFECTIVE,
/// <summary>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 .</summary>
AL_USER,
}
/// <summary>
/// Specifies the type of association for an application. Used by methods of the IApplicationAssociationRegistration interface.
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-associationtype
[PInvokeData("shobjidl_core.h")]
public enum ASSOCIATIONTYPE
{
/// <summary>Indicates a file name extension, such as .htm or .mp3.</summary>
AT_FILEEXTENSION,
/// <summary>Indicates a protocol, such as http or mailto.</summary>
AT_URLPROTOCOL,
/// <summary>
/// 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.
/// </summary>
AT_STARTMENUCLIENT,
/// <summary>Indicates the MIME type, such as audio/mp3.</summary>
AT_MIMETYPE,
}
/// <summary>One of the following values that indicate which known category to add to the list</summary>
[PInvokeData("Shobjidl.h", MSDNShortId = "dd378397")]
public enum KNOWNDESTCATEGORY
@ -191,6 +241,33 @@ namespace Vanara.PInvoke
SVGIO_FLAG_VIEWORDER = 0x80000000,
}
/// <summary>
/// <para>
/// Exposes methods that query and set default applications for specific file Association Type, and protocols at a specific
/// Association Level.
/// </para>
/// <para><c>Note</c> As of Windows 8, the only functionality of this interface that is supported is QueryCurrentDefault.</para>
/// </summary>
/// <remarks>
/// <para>
/// Because <c>IApplicationAssociationRegistration</c> 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.
/// </para>
/// </remarks>
// 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();
}
/// <summary>Exposes methods that allow an application to remove one or all destinations from the Recent or Frequent categories in a Jump List.</summary>
[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);
}
/// <summary>Exposes methods to set default icons associated with an object.</summary>
[ComImport, Guid("41ded17d-d6b3-4261-997d-88c60e4b1d58"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[PInvokeData("Shobjidl.h")]
public interface IDefaultExtractIconInit
{
/// <summary>Sets GIL_XXX flags. See GetIconLocation</summary>
/// <param name="uFlags">Specifies return flags to get icon location.</param>
void SetFlags(GetIconLocationFlags uFlags);
/// <summary>Sets the registry key from which to load the "DefaultIcon" value.</summary>
/// <param name="hkey">A handle to the registry key.</param>
void SetKey(IntPtr hkey);
/// <summary>Sets the normal icon.</summary>
/// <param name="pszFile">
/// 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.
/// </param>
/// <param name="iIcon">A Shell icon ID.</param>
void SetNormalIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon);
/// <summary>Sets the icon that allows containers to specify an "open" look.</summary>
/// <param name="pszFile">
/// 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.
/// </param>
/// <param name="iIcon">Shell icon ID.</param>
void SetOpenIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon);
/// <summary>Sets the icon for a shortcut to the object.</summary>
/// <param name="pszFile">
/// 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.
/// </param>
/// <param name="iIcon">Shell icon ID.</param>
void SetShortcutIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon);
/// <summary>Sets the default icon.</summary>
/// <param name="pszFile">
/// 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.
/// </param>
/// <param name="iIcon">The Shell icon ID.</param>
void SetDefaultIcon([In, MarshalAs(UnmanagedType.LPWStr)] string pszFile, int iIcon);
}
/// <summary>Exposes a method that allows enumeration of a collection of handlers associated with particular file name extensions.</summary>
[ComImport, Guid("973810ae-9599-4b88-9e4d-6ee98c9552da"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[PInvokeData("shobjidl_core.h", MSDNShortId = "9e173cb3-bd73-437c-8853-c13c8b6f216f")]
public interface IEnumAssocHandlers
{
/// <summary>Retrieves a specified number of elements.</summary>
/// <param name="celt">The number of elements to retrieve.</param>
/// <param name="rgelt">
/// When this method returns, contains the address of an array of IAssocHandler pointers. Each IAssocHandler represents a single handler.
/// </param>
/// <param name="pceltFetched">When this method returns, contains a pointer to the number of elements retrieved.</param>
/// <returns>If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PreserveSig]
HRESULT Next(uint celt, out IntPtr rgelt, out uint pceltFetched);
}
/// <summary>
/// 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);
/// <summary>
/// <para>Returns an enumeration object for a specified set of file name extension handlers.</para>
/// </summary>
/// <param name="pszExtra">
/// <para>Type: <c>PCWSTR</c></para>
/// <para>
/// 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 <c>NULL</c>, all handlers for all extensions are enumerated.
/// </para>
/// </param>
/// <param name="afFilter">
/// <para>Type: <c>ASSOC_FILTER</c></para>
/// <para>
/// Specifies the enumeration handler filter applied to the full list of handlers that results from the value given in . One of the
/// following values.
/// </para>
/// <para>ASSOC_FILTER_NONE</para>
/// <para>Return all handlers.</para>
/// <para>ASSOC_FILTER_RECOMMENDED</para>
/// <para>
/// 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.
/// </para>
/// </param>
/// <param name="ppEnumHandler">
/// <para>Type: <c>IEnumAssocHandlers**</c></para>
/// <para>When this method returns, contains the address of a pointer to an IEnumAssocHandlers object.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
// 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);
/// <summary>
/// <para>Gets an enumeration interface that provides access to handlers associated with a given protocol.</para>
/// </summary>
/// <param name="protocol">
/// <para>Type: <c>PCWSTR</c></para>
/// <para>Pointer to a string that specifies the protocol.</para>
/// </param>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>A reference to the IID of the interface to retrieve through , typically IID_IEnumAssocHandlers.</para>
/// </param>
/// <param name="enumHandlers">
/// <para>Type: <c>void**</c></para>
/// <para>When this method returns, contains the interface pointer requested in . This is typically IEnumAssocHandlers.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
/// <remarks>
/// <para>
/// It is recommended that you use the <c>IID_PPV_ARGS</c> 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.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// <para>Creates an IApplicationAssociationRegistration object based on the stock implementation of the interface provided by Windows.</para>
/// </summary>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>A reference to the IID of the requested interface.</para>
/// </param>
/// <param name="ppv">
/// <para>Type: <c>void**</c></para>
/// <para>When this function returns, contains the address of a pointer to the IApplicationAssociationRegistration object.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
// 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);
/// <summary>
/// <para>Creates a standard icon extractor, whose defaults can be further configured via the IDefaultExtractIconInit interface.</para>
/// </summary>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>A reference to interface ID.</para>
/// </param>
/// <param name="ppv">
/// <para>Type: <c>void**</c></para>
/// <para>The address of IDefaultExtractIconInit interface pointer.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
/// <remarks>
/// <para>The intended usage for this function is as follows:</para>
/// </remarks>
// 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);
/// <summary>
/// <para>Creates a file operation that sets the default properties on the Shell item that have not already been set.</para>
/// </summary>
/// <param name="psi">
/// <para>Type: <c>IShellItem*</c></para>
/// <para>A pointer to the source shell item. See IShellItem.</para>
/// </param>
/// <param name="ppFileOp">
/// <para>Type: <c>IFileOperation**</c></para>
/// <para>The address of the IFileOperation interface pointer.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
/// <remarks>
/// <para>
/// The list of properties to set a default value comes from the <c>SetDefaultsFor</c> 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 <c>SetDefaultsFor</c> entry does not exist on the ProgID, this function uses the default found on the <c>SetDefaultsFor</c>
/// entry of <c>HKEY_CLASSES_ROOT</c>&lt;b&gt;*.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// 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.
/// </summary>
@ -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);
/// <summary>
/// Creates a Shell item array object.
/// </summary>
@ -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);
/// <summary>
/// Creates a Shell item array object from a list of ITEMIDLIST structures.
/// </summary>
@ -766,6 +1046,10 @@ namespace Vanara.PInvoke
[PInvokeData("Shobjidl.h", MSDNShortId = "bb776437")]
internal static extern IntPtr IntILCombine(IntPtr pidl1, IntPtr pidl2);
/// <summary>Implements CLSID_ApplicationAssociationRegistration to create IApplicationAssociationRegistration.</summary>
[PInvokeData("shobjidl_core.h")]
[ComImport, Guid("591209c7-767b-42b2-9fba-44ee4615f2c7"), ClassInterface(ClassInterfaceType.None)]
public class ApplicationAssociationRegistration { }
/// <summary>Class interface for IEnumerableObjectCollection.</summary>
[ComImport, Guid("2d3468c1-36a7-43b6-ac24-d3f02fd9607a"), ClassInterface(ClassInterfaceType.None)]
public class CEnumerableObjectCollection { }

View File

@ -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
{
/// <summary>Interfaces, functions, enumerated types and structures for Shell32.dll.</summary>
public static partial class Shell32
{
/// <summary>Values used in APPBARDATA.</summary>
[PInvokeData("shellapi.h", MSDNShortId = "cf86fe15-4beb-49b7-b73e-2ad61cedc3f8")]
public enum ABE
{
/// <summary>Left edge.</summary>
ABE_LEFT = 0,
/// <summary>Top edge.</summary>
ABE_TOP = 1,
/// <summary>Right edge.</summary>
ABE_RIGHT = 2,
/// <summary>Bottom edge.</summary>
ABE_BOTTOM = 3,
}
/// <summary>Values used by SHAppBarMessage.</summary>
[PInvokeData("shellapi.h", MSDNShortId = "173d6eff-b33b-4d7d-bedd-5ebfb1e45954")]
public enum ABM
{
/// <summary>Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar.</summary>
ABM_NEW = 0x00000000,
/// <summary>Unregisters an appbar, removing the bar from the system's internal list.</summary>
ABM_REMOVE = 0x00000001,
/// <summary>Requests a size and screen position for an appbar.</summary>
ABM_QUERYPOS = 0x00000002,
/// <summary>Sets the size and screen position of an appbar.</summary>
ABM_SETPOS = 0x00000003,
/// <summary>Retrieves the autohide and always-on-top states of the Windows taskbar.</summary>
ABM_GETSTATE = 0x00000004,
/// <summary>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.</summary>
ABM_GETTASKBARPOS = 0x00000005,
/// <summary>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.</summary>
ABM_ACTIVATE = 0x00000006,
/// <summary>Retrieves the handle to the autohide appbar associated with a particular edge of the screen.</summary>
ABM_GETAUTOHIDEBAR = 0x00000007,
/// <summary>Registers or unregisters an autohide appbar for an edge of the screen.</summary>
ABM_SETAUTOHIDEBAR = 0x00000008,
/// <summary>Notifies the system when an appbar's position has changed.</summary>
ABM_WINDOWPOSCHANGED = 0x00000009,
/// <summary>Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes.</summary>
ABM_SETSTATE = 0x0000000A,
/// <summary>Windows XP and later: Retrieves the handle to the autohide appbar associated with a particular edge of a particular monitor.</summary>
ABM_GETAUTOHIDEBAREX = 0x0000000B,
/// <summary>Windows XP and later: Registers or unregisters an autohide appbar for an edge of a particular monitor.</summary>
ABM_SETAUTOHIDEBAREX = 0x0000000C,
}
/// <summary>Where to obtain association data and the form the data is stored in.</summary>
[PInvokeData("shellapi.h", MSDNShortId = "1d1a963f-7ebb-4ba6-9a97-795c8ef11ae4")]
public enum ASSOCCLASS
{
/// <summary>The hkClass member names a key found as <b>HKEY_CLASSES_ROOT</b>\ <b>SystemFileAssociations</b>\ <i>hkClass</i>.</summary>
ASSOCCLASS_SHELL_KEY = 0,
/// <summary>The hkClass member provides the full registry path of a ProgID.</summary>
ASSOCCLASS_PROGID_KEY,
/// <summary>The pszClass member names a ProgID found as <b>HKEY_CLASSES_ROOT</b>\ <i>pszClass</i>.</summary>
ASSOCCLASS_PROGID_STR,
/// <summary>The hkClass member provides the full registry path of a CLSID.</summary>
ASSOCCLASS_CLSID_KEY,
/// <summary>The hkClass member names a CLSID found as <b>HKEY_CLASSES_ROOT</b>\ <b>CLSID</b>\ <i>pszClass</i>.</summary>
ASSOCCLASS_CLSID_STR,
/// <summary>The hkClass member provides the full registry path of an application identifier (APPID).</summary>
ASSOCCLASS_APP_KEY,
/// <summary>
/// The APPID storing the application information is found at <b>HKEY_CLASSES_ROOT</b>\ <b>Applications</b>\ <i>FileName</i>
/// where <i>FileName</i> is obtained by sending <b>pszClass</b> to PathFindFileName.
/// </summary>
ASSOCCLASS_APP_STR,
/// <summary>The pszClass member names a key found as <b>HKEY_CLASSES_ROOT</b>\ <b>SystemFileAssociations</b>\ <i>pszClass</i>.</summary>
ASSOCCLASS_SYSTEM_STR,
/// <summary>
/// Use the association information for folders stored under <b>HKEY_CLASSES_ROOT</b>\ <b>Folder</b>. When this flag is set,
/// <b>hkClass</b> and <b>pszClass</b> are ignored.
/// </summary>
ASSOCCLASS_FOLDER,
/// <summary>
/// Use the association information stored under the <b>HKEY_CLASSES_ROOT</b>\ <b>*</b> subkey. When this flag is set,
/// <b>hkClass</b> and <b>pszClass</b> are ignored.
/// </summary>
ASSOCCLASS_STAR,
/// <summary>
/// Introduced in Windows 8. Do not use the user defaults to apply the mapping of the class specified by the pszClass member.
/// </summary>
ASSOCCLASS_FIXED_PROGID_STR,
/// <summary>
/// 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.
/// </summary>
ASSOCCLASS_PROTOCOL_STR,
}
/// <summary>Flags that indicate the content and validity of the other structure members in <see cref="SHELLEXECUTEINFO"/>.</summary>
[PInvokeData("Shellapi.h", MSDNShortId = "bb759784")]
[Flags]
@ -242,6 +351,332 @@ namespace Vanara.PInvoke
/// </summary>
SHGFI_OVERLAYINDEX = 0x000000040
}
/// <summary>
/// <para>Retrieves an object that implements an IQueryAssociations interface.</para>
/// </summary>
/// <param name="rgClasses">
/// <para>Type: <c>const ASSOCIATIONELEMENT*</c></para>
/// <para>A pointer to an array of ASSOCIATIONELEMENT structures.</para>
/// </param>
/// <param name="cClasses">
/// <para>Type: <c>ULONG</c></para>
/// <para>The number of elements in the array pointed to by .</para>
/// </param>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>Reference to the desired IID, normally IID_IQueryAssociations.</para>
/// </param>
/// <param name="ppv">
/// <para>Type: <c>void**</c></para>
/// <para>When this method returns, contains the interface pointer requested in . This is normally IQueryAssociations.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
/// <remarks>
/// <para>For systems earlier than Windows Vista, use the AssocCreate function.</para>
/// </remarks>
// 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);
/// <summary>
/// <para>
/// 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.
/// </para>
/// </summary>
/// <param name="lpCmdLine">
/// <para>Type: <c>LPCWSTR</c></para>
/// <para>
/// Pointer to a <c>null</c>-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.
/// </para>
/// </param>
/// <param name="pNumArgs">
/// <para>Type: <c>int*</c></para>
/// <para>Pointer to an <c>int</c> that receives the number of array elements returned, similar to .</para>
/// </param>
/// <returns>
/// <para>Type: <c>LPWSTR*</c></para>
/// <para>A pointer to an array of <c>LPWSTR</c> values, similar to .</para>
/// <para>If the function fails, the return value is <c>NULL</c>. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// The address returned by <c>CommandLineToArgvW</c> is the address of the first element in an array of <c>LPWSTR</c> values; the
/// number of pointers in this array is indicated by . Each pointer to a <c>null</c>-terminated Unicode string represents an
/// individual argument found on the command line.
/// </para>
/// <para>
/// <c>CommandLineToArgvW</c> 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.
/// </para>
/// <para>For more information about the and argument convention, see Argument Definitions and Parsing C++ Command-Line Arguments.</para>
/// <para>The GetCommandLineW function can be used to get a command line string that is suitable for use as the parameter.</para>
/// <para>
/// This function accepts command lines that contain a program name; the program name can be enclosed in quotation marks or not.
/// </para>
/// <para>
/// <c>CommandLineToArgvW</c> 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.
/// </para>
/// <para>
/// 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.
/// </para>
/// <list type="bullet">
/// <item>
/// 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.
/// </item>
/// <item>
/// (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.
/// </item>
/// <item>backslashes not followed by a quotation mark simply produce backslashes.</item>
/// </list>
/// <para>
/// <c>Important</c><c>CommandLineToArgvW</c> treats whitespace outside of quotation marks as argument delimiters. However, if starts
/// with any amount of whitespace, <c>CommandLineToArgvW</c> will consider the first argument to be an empty string. Excess
/// whitespace at the end of is ignored.
/// </para>
/// <para>Examples</para>
/// </remarks>
// 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);
/// <summary>
/// <para>Registers whether a window accepts dropped files.</para>
/// </summary>
/// <param name="hWnd">
/// <para>Type: <c>HWND</c></para>
/// <para>The identifier of the window that is registering whether it will accept dropped files.</para>
/// </param>
/// <param name="fAccept">
/// <para>Type: <c>BOOL</c></para>
/// <para>
/// A value that indicates if the window identified by the parameter accepts dropped files. This value is <c>TRUE</c> to accept
/// dropped files or <c>FALSE</c> to discontinue accepting dropped files.
/// </para>
/// </param>
/// <returns>
/// <para>No return value.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application that calls <c>DragAcceptFiles</c> with the parameter set to <c>TRUE</c> has identified itself as able to process
/// the WM_DROPFILES message from File Manager.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// <para>Releases memory that the system allocated for use in transferring file names to the application.</para>
/// </summary>
/// <param name="hDrop">
/// <para>Type: <c>HDROP</c></para>
/// <para>
/// Identifier of the structure that describes dropped files. This handle is retrieved from the parameter of the WM_DROPFILES message.
/// </para>
/// </param>
/// <returns>
/// <para>No return value.</para>
/// </returns>
// 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);
/// <summary>
/// <para>Retrieves the names of dropped files that result from a successful drag-and-drop operation.</para>
/// </summary>
/// <param name="hDrop">
/// <para>Type: <c>HDROP</c></para>
/// <para>Identifier of the structure that contains the file names of the dropped files.</para>
/// </param>
/// <param name="iFile">
/// <para>Type: <c>UINT</c></para>
/// <para>
/// Index of the file to query. If the value of this parameter is 0xFFFFFFFF, <c>DragQueryFile</c> returns a count of the files
/// dropped. If the value of this parameter is between zero and the total number of files dropped, <c>DragQueryFile</c> copies the
/// file name with the corresponding value to the buffer pointed to by the parameter.
/// </para>
/// </param>
/// <param name="lpszFile">
/// <para>Type: <c>LPTSTR</c></para>
/// <para>
/// 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 <c>NULL</c>, <c>DragQueryFile</c> returns the required size, in characters, of this buffer.
/// </para>
/// </param>
/// <param name="cch">
/// <para>Type: <c>UINT</c></para>
/// <para>The size, in characters, of the buffer.</para>
/// </param>
/// <returns>
/// <para>Type: <c>UINT</c></para>
/// <para>A nonzero value indicates a successful call.</para>
/// <para>
/// 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.
/// </para>
/// <para>
/// 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.
/// </para>
/// <para>
/// If the index value is between zero and the total number of dropped files, and the buffer address is <c>NULL</c>, the return value
/// is the required size, in characters, of the buffer, the terminating null character.
/// </para>
/// </returns>
// 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);
/// <summary>
/// <para>Retrieves the position of the mouse pointer at the time a file was dropped during a drag-and-drop operation.</para>
/// </summary>
/// <param name="hDrop">
/// <para>Type: <c>HDROP</c></para>
/// <para>Handle of the drop structure that describes the dropped file.</para>
/// </param>
/// <param name="ppt">
/// <para>TBD</para>
/// </param>
/// <returns>
/// <para>Type: <c>BOOL</c></para>
/// <para><c>TRUE</c> if the drop occurred in the client area of the window; otherwise <c>FALSE</c>.</para>
/// </returns>
/// <remarks>
/// <para>The window for which coordinates are returned is the window that received the WM_DROPFILES message.</para>
/// </remarks>
// 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);
/// <summary>Creates a duplicate of a specified icon.</summary>
/// <param name="hInst">Type: <c>HINSTANCE</c></param>
/// <param name="hIcon">
/// <para>Type: <c>HICON</c></para>
/// <para>Handle to the icon to be duplicated.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HICON</c></para>
/// <para>If successful, the function returns the handle to the new icon that was created; otherwise, <c>NULL</c>.</para>
/// </returns>
// 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);
/// <summary>
/// Gets a handle to an icon stored as a resource in a file or an icon stored in a file's associated executable file.
/// </summary>
/// <param name="hInst">A handle to the instance of the calling application.</param>
/// <param name="lpIconPath">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.
/// <para>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.</para></param>
/// <param name="lpiIcon">Pointer to a WORD value that, on entry, specifies the index of the icon whose handle is to be obtained.
/// <para>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.</para></param>
/// <returns>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.
/// <para>If the function fails, the return value is NULL.</para></returns>
// 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);
/// <summary>
/// <para>
/// 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.
/// </para>
/// </summary>
/// <param name="hInst">
/// <para>Type: <c>HINSTANCE</c></para>
/// <para>The handle of the module from which to extract the icon.</para>
/// </param>
/// <param name="pszIconPath">
/// <para>TBD</para>
/// </param>
/// <param name="piIconIndex">
/// <para>TBD</para>
/// </param>
/// <param name="piIconId">
/// <para>TBD</para>
/// </param>
/// <returns>
/// <para>Type: <c>HICON</c></para>
/// <para>Returns the icon's handle if successful, otherwise <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>The icon handle returned by this function must be released by calling DestroyIcon when it is no longer needed.</para>
/// </remarks>
// 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);
/// <summary>
/// <para>Gets a handle to an icon from the specified executable file, DLL, or icon file.</para>
/// <para>To retrieve an array of handles to large or small icons, use the <c>ExtractIconEx</c> function.</para>
/// </summary>
/// <param name="hInst">
/// <para>Type: <c>HINSTANCE</c></para>
/// <para>Handle to the instance of the application that calls the function.</para>
/// </param>
/// <param name="lpszExeFileName">
/// <para>Type: <c>LPCTSTR</c></para>
/// <para>Pointer to a null-terminated string that specifies the name of an executable file, DLL, or icon file.</para>
/// </param>
/// <param name="nIconIndex">
/// <para>Type: <c>UINT</c></para>
/// <para>
/// 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.
/// </para>
/// <para>
/// 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.
/// </para>
/// <para>
/// 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 <c>ExtractIconEx</c> function.
/// </para>
/// </param>
/// <returns>
/// <para>Type: <c>HICON</c></para>
/// <para>
/// 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 <c>NULL</c>.
/// </para>
/// </returns>
// 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);
/// <summary>
/// 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);
/// <summary>
/// <para>Retrieves the name of and handle to the executable (.exe) file associated with a specific document file.</para>
/// </summary>
/// <param name="lpFile">
/// <para>Type: <c>LPCTSTR</c></para>
/// <para>The address of a <c>null</c>-terminated string that specifies a file name. This file should be a document.</para>
/// </param>
/// <param name="lpDirectory">
/// <para>Type: <c>LPCTSTR</c></para>
/// <para>The address of a <c>null</c>-terminated string that specifies the default directory. This value can be <c>NULL</c>.</para>
/// </param>
/// <param name="lpResult">
/// <para>Type: <c>LPTSTR</c></para>
/// <para>
/// The address of a buffer that receives the file name of the associated executable file. This file name is a <c>null</c>-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 <c>Open</c> is
/// chosen from the file's shortcut menu. This parameter must contain a valid non- <c>null</c> value and is assumed to be of length
/// MAX_PATH. Responsibility for validating the value is left to the programmer.
/// </para>
/// </param>
/// <returns>
/// <para>Type: <c>HINSTANCE</c></para>
/// <para>Returns a value greater than 32 if successful, or a value less than or equal to 32 representing an error.</para>
/// <para>The following table lists possible error values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code/value</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>SE_ERR_FNF 2</term>
/// <term>The specified file was not found.</term>
/// </item>
/// <item>
/// <term>SE_ERR_PNF 3</term>
/// <term>The specified path is invalid.</term>
/// </item>
/// <item>
/// <term>SE_ERR_ACCESSDENIED 5</term>
/// <term>The specified file cannot be accessed.</term>
/// </item>
/// <item>
/// <term>SE_ERR_OOM 8</term>
/// <term>The system is out of memory or resources.</term>
/// </item>
/// <item>
/// <term>SE_ERR_NOASSOC 31</term>
/// <term>There is no association for the specified file type with an executable file.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>Use <c>FindExecutable</c> for documents. If you want to retrieve the path of an executable file, use the following:</para>
/// <para>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.</para>
/// <para>
/// When <c>FindExecutable</c> 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.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// <para>Initializes the network address control window class.</para>
/// </summary>
/// <returns>
/// <para>Type: <c>BOOL</c></para>
/// <para><c>TRUE</c> if the initialization succeeded; or <c>FALSE</c> otherwise.</para>
/// </returns>
/// <remarks>
/// <para>
/// 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.
/// </para>
/// <para>This function initializes class WC_NETADDRESS. If this function returns <c>TRUE</c>, the control can be created.</para>
/// </remarks>
// 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();
/// <summary>
/// <para>Adds default properties to the property store as registered for the specified file extension.</para>
/// </summary>
/// <param name="pszExt">
/// <para>Type: <c>PCWSTR</c></para>
/// <para>A pointer to a null-terminated, Unicode string that specifies the extension.</para>
/// </param>
/// <param name="pPropStore">
/// <para>Type: <c>IPropertyStore*</c></para>
/// <para>A pointer to the IPropertyStore interface that defines the default properties to add.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
/// <remarks>
/// <para>
/// 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 <c>System.Author</c>, <c>System.Document.DateCreated</c>, and
/// <c>System.Photo.DateTaken</c>. If the value does not exist on the ProgID, this function uses the default found on the value of <c>HKEY_CLASSES_ROOT*</c>.
/// </para>
/// <para>
/// <c>System.Author</c> has the value of the user that performed the action. <c>System.Document.DateCreated</c> and
/// <c>System.Photo.DateTaken</c> use the current date. These three properties are the only ones for which the system provides
/// special defaults.
/// </para>
/// <para>Note that there are several types of properties:</para>
/// <list type="number">
/// <item>Properties that derive from the file system (such as, size and date created)</item>
/// <item>Properties that derive from the file (such as, dimensions and number of pages)</item>
/// <item>Properties that are placed in the file (such as, author and tags)</item>
/// </list>
/// <para>
/// 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
/// </para>
/// <para>SHAddDefaultPropertiesByExt</para>
/// <para>
/// 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
/// </para>
/// <para>New</para>
/// <para>is selected from a shortcut menu.</para>
/// </remarks>
// 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);
/// <summary>
/// <para>
/// [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.]
/// </para>
/// <para>Adds pages to a property sheet extension array created by SHCreatePropSheetExtArray.</para>
/// </summary>
/// <param name="hpsxa">
/// <para>Type: <c>HPSXA</c></para>
/// <para>The array of property sheet handlers returned by SHCreatePropSheetExtArray.</para>
/// </param>
/// <param name="lpfnAddPage">
/// <para>Type: <c>LPFNADDPROPSHEETPAGE</c></para>
/// <para>
/// 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.
/// </para>
/// </param>
/// <param name="lParam">
/// <para>Type: <c>LPARAM</c></para>
/// <para>A pointer to application-defined data. This data is passed to the callback function specified by .</para>
/// </param>
/// <returns>
/// <para>Type: <c>UINT</c></para>
/// <para>Returns the number of pages actually added.</para>
/// </returns>
/// <remarks>
/// <para>This function should be called only once for the property sheet extension array named in .</para>
/// <para>This function calls each extension's IShellPropSheetExt::AddPages method. See that page for further details.</para>
/// </remarks>
// 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);
/// <summary>
/// <para>
/// [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
/// </para>
/// <para>CoTaskMemAlloc</para>
/// <para>instead.]</para>
/// </summary>
/// <param name="cb">
/// <para>Type: <c>SIZE_T</c></para>
/// <para>The number of bytes of memory to allocate.</para>
/// </param>
/// <returns>
/// <para>Type: <c>LPVOID</c></para>
/// <para>A pointer to the allocated memory.</para>
/// </returns>
/// <remarks>
/// <para>You can free this memory by calling SHFree.</para>
/// </remarks>
// 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);
/// <summary>
/// <para>Sends an appbar message to the system.</para>
/// </summary>
/// <param name="dwMessage">
/// <para>Type: <c>DWORD</c></para>
/// <para>Appbar message value to send. This parameter can be one of the following values.</para>
/// <para>ABM_NEW (0x00000000)</para>
/// <para>
/// Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar.
/// </para>
/// <para>ABM_REMOVE (0x00000001)</para>
/// <para>Unregisters an appbar, removing the bar from the system's internal list.</para>
/// <para>ABM_QUERYPOS (0x00000002)</para>
/// <para>Requests a size and screen position for an appbar.</para>
/// <para>ABM_SETPOS (0x00000003)</para>
/// <para>Sets the size and screen position of an appbar.</para>
/// <para>ABM_GETSTATE (0x00000004)</para>
/// <para>Retrieves the autohide and always-on-top states of the Windows taskbar.</para>
/// <para>ABM_GETTASKBARPOS (0x00000005)</para>
/// <para>
/// 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.
/// </para>
/// <para>ABM_ACTIVATE (0x00000006)</para>
/// <para>
/// Notifies the system to activate or deactivate an appbar. The <c>lParam</c> member of the APPBARDATA pointed to by is set to
/// <c>TRUE</c> to activate or <c>FALSE</c> to deactivate.
/// </para>
/// <para>ABM_GETAUTOHIDEBAR (0x00000007)</para>
/// <para>Retrieves the handle to the autohide appbar associated with a particular edge of the screen.</para>
/// <para>ABM_SETAUTOHIDEBAR (0x00000008)</para>
/// <para>Registers or unregisters an autohide appbar for an edge of the screen.</para>
/// <para>ABM_WINDOWPOSCHANGED (0x00000009)</para>
/// <para>Notifies the system when an appbar's position has changed.</para>
/// <para>ABM_SETSTATE (0x0000000A)</para>
/// <para><c>Windows XP and later:</c> Sets the state of the appbar's autohide and always-on-top attributes.</para>
/// <para>ABM_GETAUTOHIDEBAREX (0x0000000B)</para>
/// <para>
/// <c>Windows XP and later:</c> Retrieves the handle to the autohide appbar associated with a particular edge of a particular monitor.
/// </para>
/// <para>ABM_SETAUTOHIDEBAREX (0x0000000C)</para>
/// <para><c>Windows XP and later:</c> Registers or unregisters an autohide appbar for an edge of a particular monitor.</para>
/// </param>
/// <param name="pData">
/// <para>Type: <c>PAPPBARDATA</c></para>
/// <para>
/// 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.
/// </para>
/// </param>
/// <returns>
/// <para>Type: <c>UINT_PTR</c></para>
/// <para>
/// 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.
/// </para>
/// </returns>
// 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);
/// <summary>
/// Performs an operation on a specified file.
/// </summary>
@ -315,6 +1014,96 @@ namespace Vanara.PInvoke
public static extern IntPtr SHGetFileInfo(PIDL itemIdList, FileAttributes dwFileAttributes, ref SHFILEINFO psfi,
int cbFileInfo, SHGFI uFlags);
/// <summary>
/// <para>Contains information about a system appbar message.</para>
/// </summary>
// 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
{
/// <summary>
/// <para>Type: <c>DWORD</c></para>
/// <para>The size of the structure, in bytes.</para>
/// </summary>
public uint cbSize;
/// <summary>
/// <para>Type: <c>HWND</c></para>
/// <para>
/// 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 <c>hWind</c> value.
/// </para>
/// </summary>
public IntPtr hWnd;
/// <summary>
/// <para>Type: <c>LPARAM</c></para>
/// <para>A message-dependent value. This member is used with these messages:</para>
/// <para>ABM_SETAUTOHIDEBAR</para>
/// <para>ABM_SETAUTOHIDEBAREX</para>
/// <para>ABM_SETSTATE</para>
/// <para>See the individual message pages for details.</para>
/// </summary>
public IntPtr lParam;
/// <summary>
/// <para>Type: <c>RECT</c></para>
/// <para>A RECT structure whose use varies depending on the message:</para>
/// <list type="bullet">
/// <item>
/// ABM_GETTASKBARPOS, ABM_QUERYPOS, ABM_SETPOS: The bounding rectangle, in screen coordinates, of an appbar or the Windows taskbar.
/// </item>
/// <item>
/// ABM_GETAUTOHIDEBAREX, ABM_SETAUTOHIDEBAREX: The monitor on which the operation is being performed. This information can be
/// retrieved through the GetMonitorInfo function.
/// </item>
/// </list>
/// </summary>
public RECT rc;
/// <summary>
/// <para>Type: <c>UINT</c></para>
/// <para>
/// An application-defined message identifier. The application uses the specified identifier for notification messages that it
/// sends to the appbar identified by the <c>hWnd</c> member. This member is used when sending the ABM_NEW message.
/// </para>
/// </summary>
public uint uCallbackMessage;
/// <summary>
/// <para>Type: <c>UINT</c></para>
/// <para>A value that specifies an edge of the screen. This member is used when sending one of these messages:</para>
/// <para>ABM_GETAUTOHIDEBAR</para>
/// <para>ABM_SETAUTOHIDEBAR</para>
/// <para>ABM_GETAUTOHIDEBAREX</para>
/// <para>ABM_SETAUTOHIDEBAREX</para>
/// <para>ABM_QUERYPOS</para>
/// <para>ABM_SETPOS</para>
/// <para>This member can be one of the following values.</para>
/// <para>ABE_BOTTOM</para>
/// <para>Bottom edge.</para>
/// <para>ABE_LEFT</para>
/// <para>Left edge.</para>
/// <para>ABE_RIGHT</para>
/// <para>Right edge.</para>
/// <para>ABE_TOP</para>
/// <para>Top edge.</para>
/// </summary>
public ABE uEdge;
}
/// <summary>Defines information used by AssocCreateForClasses to retrieve an IQueryAssociations interface for a given file association.</summary>
[PInvokeData("shellapi.h", MSDNShortId = "1d1a963f-7ebb-4ba6-9a97-795c8ef11ae4")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ASSOCIATIONELEMENT
{
/// <summary>
/// Where to obtain association data and the form the data is stored in. One of the following values from the ASSOCCLASS enumeration.
/// </summary>
public ASSOCCLASS ac;
/// <summary>A registry key that specifies a class that contains association information.</summary>
public IntPtr hkClass;
/// <summary>A pointer to the name of a class that contains association information.</summary>
public string pszClass;
}
/// <summary>
/// Contains information used by ShellExecuteEx.
/// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -58,5 +58,6 @@ IAutoComplete, IAutoComplete2, IExtractIcon, IOpenControlPanel, IApplicationDest
<ProjectReference Include="..\Ole\Vanara.PInvoke.Ole.csproj" />
<ProjectReference Include="..\Security\Vanara.PInvoke.Security.csproj" />
<ProjectReference Include="..\Shared\Vanara.PInvoke.Shared.csproj" />
<ProjectReference Include="..\ShlwApi\Vanara.PInvoke.ShlwApi.csproj" />
</ItemGroup>
</Project>

View File

@ -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);
/// <summary>
/// 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.
/// </summary>
// 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
{
/// <summary>
/// Initializes the IQueryAssociations interface and sets the root key to the appropriate ProgID.
/// </summary>
/// <param name="flags">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.</param>
/// <param name="pszAssoc">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:
/// <list type="bullet">
/// <item><term>File name extension</term><description>A file name extension, such as .txt.</description></item>
/// <item><term>CLSID</term><description>A CLSID GUID in the standard "{GUID}" format.</description></item>
/// <item><term>ProgID</term><description>An application's ProgID, such as Word.Document.8.</description></item>
/// <item><term>Executable name</term><description>The name of an application's .exe file. The ASSOCF_OPEN_BYEXENAME flag must be set in flags.</description></item>
/// </list></param>
/// <param name="hkProgid">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.</param>
/// <param name="hwnd">The HWND.</param>
void Init(ASSOCF flags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszAssoc, [Optional] IntPtr hkProgid, [Optional] IntPtr hwnd);
/// <summary>
/// Searches for and retrieves a file or protocol association-related string from the registry.
/// </summary>
/// <param name="flags">A flag that can be used to control the search. It can be any combination of the following ASSOCF values.</param>
/// <param name="str">An ASSOCSTR value that specifies the type of string that is to be returned.</param>
/// <param name="pszExtra">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.</param>
/// <param name="pszOut">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.</param>
/// <param name="pcchOut">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.
/// <para>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.</para>
/// <para>If pwszOut is NULL, the function returns S_FALSE and pcchOut points to the required size of the buffer.</para></param>
void GetString(ASSOCF flags, ASSOCSTR str, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszExtra, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszOut, ref uint pcchOut);
/// <summary>
/// Searches for and retrieves a file or protocol association-related key from the registry.
/// </summary>
/// <param name="flags">The ASSOCF value that can be used to control the search.</param>
/// <param name="data">The ASSOCKEY value that specifies the type of key that is to be returned.</param>
/// <param name="pszExtra">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.</param>
/// <param name="phkeyOut">A pointer to the key's HKEY value.</param>
void GetKey(ASSOCF flags, ASSOCKEY key, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszExtra, out IntPtr phkeyOut);
/// <summary>
/// Searches for and retrieves file or protocol association-related binary data from the registry.
/// </summary>
/// <param name="flags">The ASSOCF value that can be used to control the search.</param>
/// <param name="data">The ASSOCDATA value that specifies the type of data that is to be returned.</param>
/// <param name="pszExtra">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.</param>
/// <param name="pvOut">A pointer to a value that, when this method returns successfully, receives the requested data value.</param>
/// <param name="pcbOut">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.</param>
void GetData(ASSOCF flags, ASSOCDATA data, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pszExtra, IntPtr pvOut, ref uint pcbOut);
/// <summary>
/// This method is not implemented.
/// </summary>
/// <param name="flags">Undocumented.</param>
/// <param name="assocenum">Undocumented.</param>
/// <param name="pszExtra">Undocumented.</param>
/// <param name="riid">Undocumented.</param>
/// <param name="ppvOut">Undocumented.</param>
void GetEnum(ASSOCF flags, ASSOCENUM assocenum, [MarshalAs(UnmanagedType.LPWStr)] string pszExtra, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr ppvOut);
}
/// <summary>Provides information to the <c>IQueryAssociations</c> interface methods.</summary>
// 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
{
/// <summary>None of the following options are set.</summary>
ASSOCF_NONE = 0x00000000,
/// <summary>Instructs <c>IQueryAssociations</c> interface methods not to map CLSID values to ProgID values.</summary>
ASSOCF_INIT_NOREMAPCLSID = 0x00000001,
/// <summary>Identifies the value of the pwszAssoc parameter of <c>IQueryAssociations::Init</c> as an executable file name. If this flag is not set, the root key will be set to the ProgID associated with the <c>.exe</c> key instead of the executable file&#39;s ProgID.</summary>
ASSOCF_INIT_BYEXENAME = 0x00000002,
/// <summary>Identical to <c><c>ASSOCF_INIT_BYEXENAME</c></c>.</summary>
ASSOCF_OPEN_BYEXENAME = 0x00000002,
/// <summary>Specifies that when an <c>IQueryAssociations</c> method does not find the requested value under the root key, it should attempt to retrieve the comparable value from the <c>*</c> subkey.</summary>
ASSOCF_INIT_DEFAULTTOSTAR = 0x00000004,
/// <summary>Specifies that when a <c>IQueryAssociations</c> method does not find the requested value under the root key, it should attempt to retrieve the comparable value from the <c>Folder</c> subkey.</summary>
ASSOCF_INIT_DEFAULTTOFOLDER = 0x00000008,
/// <summary>Specifies that only <c>HKEY_CLASSES_ROOT</c> should be searched, and that <c>HKEY_CURRENT_USER</c> should be ignored.</summary>
ASSOCF_NOUSERSETTINGS = 0x00000010,
/// <summary>
/// Specifies that the return string should not be truncated. Instead, return an error value and the required size for the
/// complete string.
/// </summary>
ASSOCF_NOTRUNCATE = 0x00000020,
/// <summary>Specifies that the return string should not be truncated. Instead, return an error value and the required size for the complete string.</summary>
ASSOCF_VERIFY = 0x00000040,
/// <summary>Instructs <c>IQueryAssociations</c> methods to ignore Rundll.exe and return information about its target. Typically <c>IQueryAssociations</c> 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.</summary>
ASSOCF_REMAPRUNDLL = 0x00000080,
/// <summary>Instructs <c>IQueryAssociations</c> 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.</summary>
ASSOCF_NOFIXUPS = 0x00000100,
/// <summary>Specifies that the BaseClass value should be ignored.</summary>
ASSOCF_IGNOREBASECLASS = 0x00000200,
/// <summary><c>Introduced in Windows 7</c>. Specifies that the &quot;Unknown&quot; ProgID should be ignored; instead, fail.</summary>
ASSOCF_INIT_IGNOREUNKNOWN = 0x00000400,
/// <summary><c>Introduced in Windows 8</c>. Specifies that the supplied ProgID should be mapped using the system defaults, rather than the current user defaults.</summary>
ASSOCF_INIT_FIXED_PROGID = 0x00000800,
/// <summary><c>Introduced in Windows 8</c>. Specifies that the value is a protocol, and should be mapped using the current user defaults.</summary>
ASSOCF_IS_PROTOCOL = 0x00001000,
/// <summary><c>Introduced in Windows 8.1</c>. Specifies that the ProgID corresponds with a file extension based association. Use together with <c>ASSOCF_INIT_FIXED_PROGID</c>.</summary>
ASSOCF_INIT_FOR_FILE = 0x00002000
}
/// <summary><para>Used by IQueryAssociations::GetString to define the type of string that is to be returned.</para></summary>
// 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
{
/// <summary>A command string associated with a Shell verb.</summary>
ASSOCSTR_COMMAND = 1,
/// <summary>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.</summary>
ASSOCSTR_EXECUTABLE,
/// <summary>The friendly name of a document type.</summary>
ASSOCSTR_FRIENDLYDOCNAME,
/// <summary>The friendly name of an executable file.</summary>
ASSOCSTR_FRIENDLYAPPNAME,
/// <summary>Ignore the information associated with the open subkey.</summary>
ASSOCSTR_NOOPEN,
/// <summary>Look under the ShellNew subkey.</summary>
ASSOCSTR_SHELLNEWVALUE,
/// <summary>The DDE command to use to create a process.</summary>
ASSOCSTR_DDEIFEXEC,
/// <summary>The application name in a DDE broadcast.</summary>
ASSOCSTR_DDEAPPLICATION,
/// <summary>The topic name in a DDE broadcast.</summary>
ASSOCSTR_DDETOPIC,
/// <summary>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.</summary>
ASSOCSTR_INFOTIP,
/// <summary>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.</summary>
ASSOCSTR_QUICKTIP,
/// <summary>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.</summary>
ASSOCSTR_TILEINFO,
/// <summary>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.</summary>
ASSOCSTR_CONTENTTYPE,
/// <summary>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&#39;s resource table, while negative numbers indicate a resource ID. An example of the syntax for the resource is &quot;c:\myfolder\myfile.dll,-1&quot;.</summary>
ASSOCSTR_DEFAULTICON,
/// <summary>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 &quot;{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}&quot;, which is the IID of IExtractImage.</summary>
ASSOCSTR_SHELLEXTENSION,
/// <summary>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&#39;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.</summary>
ASSOCSTR_DROPTARGET,
/// <summary>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&#39;s CLSID. This CLSID is registered in the verb&#39;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.</summary>
ASSOCSTR_DELEGATEEXECUTE,
/// <summary>Introduced in Windows 8.</summary>
ASSOCSTR_SUPPORTED_URI_PROTOCOLS,
/// <summary>The ProgID provided by the app associated with the file type or URI scheme. This if configured by users in their default program settings.</summary>
ASSOCSTR_PROGID,
/// <summary>The AppUserModelID of the app associated with the file type or URI scheme. This is configured by users in their default program settings.</summary>
ASSOCSTR_APPID,
/// <summary>The publisher of the app associated with the file type or URI scheme. This is configured by users in their default program settings.</summary>
ASSOCSTR_APPPUBLISHER,
/// <summary>The icon reference of the app associated with the file type or URI scheme. This is configured by users in their default program settings.</summary>
ASSOCSTR_APPICONREFERENCE,
/// <summary>The maximum defined ASSOCSTR value, used for validation purposes.</summary>
ASSOCSTR_MAX,
}
/// <summary><para>Specifies the type of key to be returned by IQueryAssociations::GetKey.</para></summary>
// 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
{
/// <summary>A key that is passed to ShellExecuteEx through a SHELLEXECUTEINFO structure.</summary>
ASSOCKEY_SHELLEXECCLASS = 1,
/// <summary>An Application key for the file type.</summary>
ASSOCKEY_APP,
/// <summary>A ProgID or class key.</summary>
ASSOCKEY_CLASS,
/// <summary>A BaseClass value.</summary>
ASSOCKEY_BASECLASS,
/// <summary />
ASSOCKEY_MAX,
}
/// <summary><para>Used by IQueryAssociations::GetData to define the type of data that is to be returned.</para></summary>
// 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
{
/// <summary>The component descriptor to pass to the Windows Installer API.</summary>
ASSOCDATA_MSIDESCRIPTOR = 1,
/// <summary>Attempts to activate a window are restricted. There is no data associated with this value.</summary>
ASSOCDATA_NOACTIVATEHANDLER,
/// <summary />
ASSOCDATA_UNUSED1,
/// <summary>Defaults to user specified association.</summary>
ASSOCDATA_HASPERUSERASSOC,
/// <summary>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.</summary>
ASSOCDATA_EDITFLAGS,
/// <summary>Internet Explorer version 6 or later. Uses the parameter from the IQueryAssociations::GetData method as the value name.</summary>
ASSOCDATA_VALUE,
/// <summary />
ASSOCDATA_MAX,
}
/// <summary><para>Used by IQueryAssociations::GetEnum to define the type of enum that is to be returned.</para></summary>
public enum ASSOCENUM
{
/// <summary>Nothing.</summary>
ASSOCENUM_NONE
}
}
}