Added generic helper functions for those where a COM interface is requested

pull/38/head
David Hall 2019-01-20 20:44:04 -08:00
parent 62ef41cd2d
commit 3cade3a2a8
4 changed files with 478 additions and 58 deletions

View File

@ -350,6 +350,8 @@ namespace Vanara.PInvoke
/// <summary>Not used.</summary>
public const string STR_TRACK_CLSID = "Track the CLSID";
private delegate HRESULT IidFunc(in Guid riid, out object ppv);
/// <summary>Values that specify from which category the list of destinations should be retrieved.</summary>
[PInvokeData("Shobjidl.h", MSDNShortId = "dd378410")]
public enum APPDOCLISTTYPE
@ -1326,17 +1328,28 @@ namespace Vanara.PInvoke
[PInvokeData("shobjidl_core.h", MSDNShortId = "8bc3b9ce-5909-46a0-b5f1-35ab808aaa55")]
public static extern HRESULT SHAssocEnumHandlersForProtocolByApplication([MarshalAs(UnmanagedType.LPWStr)] string protocol, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object enumHandlers);
/// <summary>Gets an enumeration interface that provides access to handlers associated with a given protocol.</summary>
/// <typeparam name="TIntf">The type of the interface to retrieve, typically IID_IEnumAssocHandlers.</typeparam>
/// <param name="protocol"><para>Type: <c>PCWSTR</c></para>
/// <para>Pointer to a string that specifies the protocol.</para></param>
/// <returns>
/// When this method returns, contains the interface pointer requested in <typeparamref name="TIntf" />. This is typically IEnumAssocHandlers.
/// </returns>
/// <remarks>
/// 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.
/// </remarks>
[PInvokeData("shobjidl_core.h", MSDNShortId = "8bc3b9ce-5909-46a0-b5f1-35ab808aaa55")]
public static TIntf SHAssocEnumHandlersForProtocolByApplication<TIntf>(string protocol) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHAssocEnumHandlersForProtocolByApplication(protocol, g, out o));
/// <summary>
/// <para>Creates an IApplicationAssociationRegistration object based on the stock implementation of the interface provided by Windows.</para>
/// Creates an IApplicationAssociationRegistration object based on the stock implementation of the interface provided by Windows.
/// </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>
/// <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>
@ -1347,6 +1360,21 @@ namespace Vanara.PInvoke
[PInvokeData("shobjidl_core.h", MSDNShortId = "7998f49d-2515-4c77-991e-62c0fefa43df")]
public static extern HRESULT SHCreateAssociationRegistration(in Guid riid, out IApplicationAssociationRegistration ppv);
/// <summary>
/// Creates an IApplicationAssociationRegistration object based on the stock implementation of the interface provided by Windows.
/// </summary>
/// <returns>
/// When this function returns, contains the address of a pointer to the IApplicationAssociationRegistration object.
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shcreateassociationregistration SHSTDAPI
// SHCreateAssociationRegistration( REFIID riid, void **ppv );
[PInvokeData("shobjidl_core.h", MSDNShortId = "7998f49d-2515-4c77-991e-62c0fefa43df")]
public static IApplicationAssociationRegistration SHCreateAssociationRegistration()
{
SHCreateAssociationRegistration(typeof(IApplicationAssociationRegistration).GUID, out var ppv).ThrowIfFailed();
return ppv;
}
/// <summary>
/// <para>Creates a standard icon extractor, whose defaults can be further configured via the IDefaultExtractIconInit interface.</para>
/// </summary>
@ -1419,13 +1447,14 @@ namespace Vanara.PInvoke
/// 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>
/// <typeparam name="T">The type of the requested interface.</typeparam>
/// <typeparam name="TIntf">The type of the requested interface. This will typically be IShellItem or IShellItem2.</typeparam>
/// <param name="pidl">The source PIDL.</param>
/// <returns>
/// When this function returns, contains the interface pointer requested in <typeparamref name="T"/>. This will typically be IShellItem or IShellItem2.
/// When this function returns, contains the interface pointer requested.
/// </returns>
[PInvokeData("Shobjidl.h", MSDNShortId = "bb762133")]
public static T SHCreateItemFromIDList<T>(PIDL pidl) where T : class { SHCreateItemFromIDList(pidl, typeof(T).GUID, out var ppv).ThrowIfFailed(); return (T)ppv; }
public static TIntf SHCreateItemFromIDList<TIntf>(PIDL pidl) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHCreateItemFromIDList(pidl, g, out o));
/// <summary>Creates and initializes a Shell item object from a parsing name.</summary>
/// <param name="pszPath">A pointer to a display name.</param>
@ -1471,7 +1500,8 @@ namespace Vanara.PInvoke
/// When this method returns successfully, contains the interface pointer requested in <typeparamref name="T"/>. This is typically IShellItem or IShellItem2.
/// </returns>
[PInvokeData("Shlobjidl.h", MSDNShortId = "bb762134")]
public static T SHCreateItemFromParsingName<T>(string pszPath, IBindCtx pbc = null) where T : class { SHCreateItemFromParsingName(pszPath, pbc, typeof(T).GUID, out var ppv).ThrowIfFailed(); return (T)ppv; }
public static T SHCreateItemFromParsingName<T>(string pszPath, IBindCtx pbc = null) where T : class =>
IidGetObj<T>((in Guid g, out object o) => SHCreateItemFromParsingName(pszPath, pbc, g, out o));
/// <summary>Creates and initializes a Shell item object from a relative parsing name.</summary>
/// <param name="psiParent">A pointer to the parent Shell item.</param>
@ -1489,6 +1519,21 @@ namespace Vanara.PInvoke
public static extern HRESULT SHCreateItemFromRelativeName([In, MarshalAs(UnmanagedType.Interface)] IShellItem psiParent, [In, MarshalAs(UnmanagedType.LPWStr)] string pszName,
[In, MarshalAs(UnmanagedType.Interface)] IBindCtx pbc, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 3)] out object ppv);
/// <summary>Creates and initializes a Shell item object from a relative parsing name.</summary>
/// <typeparam name="TIntf">The type of the requested interface. This will typically be IShellItem or IShellItem2.</typeparam>
/// <param name="psiParent">A pointer to the parent Shell item.</param>
/// <param name="pszName">
/// A pointer to a null-terminated, Unicode string that specifies a display name that is relative to the psiParent.
/// </param>
/// <param name="pbc">A pointer to a bind context that controls the parsing operation. This parameter can be NULL.</param>
/// <returns>
/// When this function returns, contains the interface pointer requested in riid. This will usually be IShellItem or IShellItem2.
/// </returns>
[SecurityCritical, SuppressUnmanagedCodeSecurity]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb762135")]
public static TIntf SHCreateItemFromRelativeName<TIntf>(IShellItem psiParent, string pszName, IBindCtx pbc = null) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHCreateItemFromRelativeName(psiParent, pszName, pbc, g, out o));
/// <summary>Creates a Shell item object for a single file that exists inside a known folder.</summary>
/// <param name="kfid">A reference to the KNOWNFOLDERID, a GUID that identifies the folder that contains the item.</param>
/// <param name="dwKFFlags">
@ -1508,6 +1553,24 @@ namespace Vanara.PInvoke
public static extern HRESULT SHCreateItemInKnownFolder(in Guid kfid, [In] KNOWN_FOLDER_FLAG dwKFFlags,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszItem, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 3)] out object ppv);
/// <summary>Creates a Shell item object for a single file that exists inside a known folder.</summary>
/// <typeparam name="TIntf">The type of the requested interface. This will typically be IShellItem or IShellItem2.</typeparam>
/// <param name="kfid">A reference to the KNOWNFOLDERID that identifies the folder that contains the item.</param>
/// <param name="dwKFFlags">
/// Flags that specify special options in the object retrieval. This value can be 0; otherwise, one or more of the KNOWN_FOLDER_FLAG values.
/// </param>
/// <param name="pszItem">
/// A pointer to a null-terminated buffer that contains the file name of the new item as a Unicode string. This parameter can also be
/// NULL. In this case, an IShellItem that represents the known folder itself is created.
/// </param>
/// <returns>
/// When this function returns, contains the interface pointer requested in riid. This will usually be IShellItem or IShellItem2.
/// </returns>
[SecurityCritical, SuppressUnmanagedCodeSecurity]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb762136")]
public static TIntf SHCreateItemInKnownFolder<TIntf>(KNOWNFOLDERID kfid, KNOWN_FOLDER_FLAG dwKFFlags = 0, string pszItem = null) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHCreateItemInKnownFolder(kfid.Guid(), dwKFFlags, pszItem, g, out o));
/// <summary>Create a Shell item, given a parent folder and a child item ID.</summary>
/// <param name="pidlParent">
/// The IDList of the parent folder of the item being created; the IDList of psfParent. This parameter can be NULL, if psfParent is specified.
@ -1527,6 +1590,35 @@ namespace Vanara.PInvoke
public static extern HRESULT SHCreateItemWithParent([In] PIDL pidlParent, [In, MarshalAs(UnmanagedType.Interface)] IShellFolder psfParent,
[In] PIDL pidl, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 3)] out object ppvItem);
/// <summary>Create a Shell item, given a parent folder and a child item ID.</summary>
/// <typeparam name="TIntf">The type of the requested interface. This will typically be IShellItem or IShellItem2.</typeparam>
/// <param name="pidlParent">
/// The IDList of the parent folder of the item being created; the IDList of psfParent. This parameter cannot be NULL.
/// </param>
/// <param name="pidl">A child item ID relative to its parent folder specified by psfParent or pidlParent.</param>
/// <returns>
/// When this function returns, contains the interface pointer requested in riid. This will usually be IShellItem or IShellItem2.
/// </returns>
[SecurityCritical, SuppressUnmanagedCodeSecurity]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb762137")]
public static TIntf SHCreateItemWithParent<TIntf>(PIDL pidlParent, PIDL pidl) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHCreateItemWithParent(pidlParent, null, pidl, g, out o));
/// <summary>Create a Shell item, given a parent folder and a child item ID.</summary>
/// <typeparam name="TIntf">The type of the requested interface. This will typically be IShellItem or IShellItem2.</typeparam>
/// <param name="psfParent">
/// A pointer to IShellFolder interface that specifies the shell data source of the child item specified by the pidl. This parameter
/// cannot be NULL.
/// </param>
/// <param name="pidl">A child item ID relative to its parent folder specified by psfParent or pidlParent.</param>
/// <returns>
/// When this function returns, contains the interface pointer requested in riid. This will usually be IShellItem or IShellItem2.
/// </returns>
[SecurityCritical, SuppressUnmanagedCodeSecurity]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb762137")]
public static TIntf SHCreateItemWithParent<TIntf>(IShellFolder psfParent, PIDL pidl) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHCreateItemWithParent(null, psfParent, pidl, g, out o));
/// <summary>Creates a Shell item array object.</summary>
/// <param name="pidlParent">
/// The ID list of the parent folder of the items specified in ppidl. If psf is specified, this parameter can be NULL. If this
@ -1588,9 +1680,37 @@ namespace Vanara.PInvoke
[PInvokeData("shobjidl_core.h", MSDNShortId = "91e65c9a-0600-42e3-97f5-2a5960e1ec89")]
public static extern HRESULT SHCreateShellItemArrayFromDataObject(IDataObject pdo, in Guid riid, out IShellItemArray ppv);
// [DllImport(Lib.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true)] [SecurityCritical, SuppressUnmanagedCodeSecurity]
// [PInvokeData("Shlobj.h", MSDNShortId = "bb762141")] public static extern HRESULT SHCreateShellFolderView(in SFV_CREATE pcsfv,
// [MarshalAs(UnmanagedType.Interface)] out object ppvItem);
/// <summary>Creates a Shell item array object from a data object.</summary>
/// <param name="pdo"><para>Type: <c>IDataObject*</c></para>
/// <para>A pointer to IDataObject interface.</para></param>
/// <returns>
/// When this method returns, contains the interface pointer requested. This is typically IShellItemArray.
/// </returns>
/// <remarks>
/// <para>
/// This function is useful for Shell extensions that implement IShellExtInit and are passed a data object to the
/// IShellExtInit::Initialize method; for example, context menu handlers.
/// </para>
/// <para>
/// This API lets you convert the data object into a Shell item that the handler can consume. It is recommend that handlers use a
/// Shell item array rather than clipboard formats like <c>CF_HDROP</c> and <c>CFSTR_SHELLIDLIST</c> (also known as HIDA) as it leads
/// to simpler code and allows some performance improvements.
/// </para>
/// <para>
/// The resulting shell item array holds a reference to the source data object. Therefore, that data object must remain valid for the
/// lifetime of the shell item array. Notably, the data objects passed to IDropTarget methods are no longer valid after the drop
/// operation completes.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shcreateshellitemarrayfromdataobject SHSTDAPI
// SHCreateShellItemArrayFromDataObject( IDataObject *pdo, REFIID riid, void **ppv );
[PInvokeData("shobjidl_core.h", MSDNShortId = "91e65c9a-0600-42e3-97f5-2a5960e1ec89")]
public static IShellItemArray SHCreateShellItemArrayFromDataObject(IDataObject pdo)
{
SHCreateShellItemArrayFromDataObject(pdo, typeof(IShellItemArray).GUID, out var o).ThrowIfFailed();
return o;
}
/// <summary>Creates a Shell item array object from a list of ITEMIDLIST structures.</summary>
/// <param name="cidl">The number of elements in the array.</param>
/// <param name="rgpidl">A list of cidl constant pointers to ITEMIDLIST structures.</param>
@ -1665,6 +1785,21 @@ namespace Vanara.PInvoke
[PInvokeData("shobjidl_core.h", MSDNShortId = "1d7b9ffa-9980-4d68-85e4-7bab667be168")]
public static extern HRESULT SHGetItemFromDataObject(IDataObject pdtobj, DATAOBJ_GET_ITEM_FLAGS dwFlags, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] out object ppv);
/// <summary>Creates an IShellItem or related object based on an item specified by an IDataObject.</summary>
/// <typeparam name="TIntf">The type of the requested interface. This will typically be IShellItem or IShellItem2.</typeparam>
/// <param name="pdtobj"><para>Type: <c>IDataObject*</c></para>
/// <para>A pointer to the source IDataObject instance.</para></param>
/// <param name="dwFlags"><para>Type: <c>DATAOBJ_GET_ITEM_FLAGS</c></para>
/// <para>
/// One or more values from the DATAOBJ_GET_ITEM_FLAGS enumeration to specify options regarding the target object. This value can be 0.
/// </para></param>
/// <returns>When this method returns, contains the interface pointer requested. This is typically IShellItem.</returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shgetitemfromdataobject HRESULT
// SHGetItemFromDataObject( IDataObject *pdtobj, DATAOBJ_GET_ITEM_FLAGS dwFlags, REFIID riid, void **ppv );
[PInvokeData("shobjidl_core.h", MSDNShortId = "1d7b9ffa-9980-4d68-85e4-7bab667be168")]
public static TIntf SHGetItemFromDataObject<TIntf>(IDataObject pdtobj, DATAOBJ_GET_ITEM_FLAGS dwFlags) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHGetItemFromDataObject(pdtobj, dwFlags, g, out o));
/// <summary>
/// <para>Retrieves an IShellItem for an object.</para>
/// </summary>
@ -1696,6 +1831,23 @@ namespace Vanara.PInvoke
[PInvokeData("shobjidl_core.h", MSDNShortId = "0ef494c0-81c7-4fbd-9c37-78861d8ac63b")]
public static extern HRESULT SHGetItemFromObject([MarshalAs(UnmanagedType.IUnknown)] object punk, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 1)] out object ppv);
/// <summary>Retrieves an IShellItem for an object.</summary>
/// <typeparam name="TIntf">The type of the requested interface. This is typically IShellItem or a related interface.</typeparam>
/// <param name="punk"><para>Type: <c>IUnknown*</c></para>
/// <para>A pointer to the IUnknown of the object.</para></param>
/// <returns>
/// When this method returns, contains the interface pointer requested. This is typically IShellItem or a related interface.
/// </returns>
/// <remarks>
/// From the standpoint of performance, this method is preferred to SHGetIDListFromObject in those cases where the IDList is already
/// bound to a folder.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shgetitemfromobject SHSTDAPI
// SHGetItemFromObject( IUnknown *punk, REFIID riid, void **ppv );
[PInvokeData("shobjidl_core.h", MSDNShortId = "0ef494c0-81c7-4fbd-9c37-78861d8ac63b")]
public static TIntf SHGetItemFromObject<TIntf>(object punk) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHGetItemFromObject(punk, g, out o));
/// <summary>
/// <para>Retrieves an object that supports IPropertyStore or related interfaces from a pointer to an item identifier list (PIDL).</para>
/// </summary>
@ -1726,6 +1878,23 @@ namespace Vanara.PInvoke
[PInvokeData("shobjidl_core.h", MSDNShortId = "2a3c3c80-1bfc-4da0-ba6e-ac9e9a5c3e5b")]
public static extern HRESULT SHGetPropertyStoreFromIDList(PIDL pidl, GETPROPERTYSTOREFLAGS flags, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] out object ppv);
/// <summary>
/// Retrieves an object that supports IPropertyStore or related interfaces from a pointer to an item identifier list (PIDL).
/// </summary>
/// <typeparam name="TIntf">The type of the requested interface. This is typically IPropertyStore or a related interface.</typeparam>
/// <param name="pidl"><para>Type: <c>PCIDLIST_ABSOLUTE</c></para>
/// <para>A pointer to an item ID list.</para></param>
/// <param name="flags"><para>Type: <c>GETPROPERTYSTOREFLAGS</c></para>
/// <para>One or more values from the GETPROPERTYSTOREFLAGS constants. This parameter can also be <c>NULL</c>.</para></param>
/// <returns>
/// When this function returns, contains the interface pointer requested. This is typically IPropertyStore or a related interface.
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-shgetpropertystorefromidlist SHSTDAPI
// SHGetPropertyStoreFromIDList( PCIDLIST_ABSOLUTE pidl, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv );
[PInvokeData("shobjidl_core.h", MSDNShortId = "2a3c3c80-1bfc-4da0-ba6e-ac9e9a5c3e5b")]
public static TIntf SHGetPropertyStoreFromIDList<TIntf>(PIDL pidl, GETPROPERTYSTOREFLAGS flags) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHGetPropertyStoreFromIDList(pidl, flags, g, out o));
/// <summary>Returns a property store for an item, given a path or parsing name.</summary>
/// <param name="pszPath">A pointer to a null-terminated Unicode string that specifies the item path.</param>
/// <param name="pbc">A pointer to a IBindCtx object, which provides access to a bind context. This value can be NULL.</param>
@ -1894,6 +2063,12 @@ namespace Vanara.PInvoke
[PInvokeData("Shobjidl.h", MSDNShortId = "bb776437")]
internal static extern IntPtr IntILCombine(IntPtr pidl1, IntPtr pidl2);
private static T IidGetObj<T>(IidFunc f) where T : class
{
f(typeof(T).GUID, out var ppv).ThrowIfFailed();
return (T)ppv;
}
/// <summary>Implements CLSID_ApplicationAssociationRegistration to create IApplicationAssociationRegistration.</summary>
[PInvokeData("shobjidl_core.h")]
[ComImport, Guid("591209c7-767b-42b2-9fba-44ee4615f2c7"), ClassInterface(ClassInterfaceType.None)]

View File

@ -1133,6 +1133,20 @@ namespace Vanara.PInvoke
[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 Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
/// <summary>Retrieves an object that implements an IQueryAssociations interface.</summary>
/// <typeparam name="TIntf">Reference to the desired IID type, normally IQueryAssociations.</typeparam>
/// <param name="rgClasses"><para>Type: <c>const ASSOCIATIONELEMENT*</c></para>
/// <para>A pointer to an array of ASSOCIATIONELEMENT structures.</para></param>
/// <returns>
/// When this method returns, contains the interface pointer requested in . This is normally IQueryAssociations.
/// </returns>
/// <remarks>For systems earlier than Windows Vista, use the AssocCreate function.</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 );
[PInvokeData("shellapi.h", MSDNShortId = "43257507-dd5e-4622-8445-c132187fd1e5")]
public static TIntf AssocCreateForClasses<TIntf>(ASSOCIATIONELEMENT[] rgClasses) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => AssocCreateForClasses(rgClasses, (uint)(rgClasses?.Length ?? 0), g, out o));
/// <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
@ -2685,6 +2699,50 @@ namespace Vanara.PInvoke
[PInvokeData("shellapi.h", MSDNShortId = "772aa2c8-6dd1-480c-a008-58f30902cb80")]
public static extern HRESULT SHGetPropertyStoreForWindow(HWND hwnd, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
/// <summary>
/// Retrieves an object that represents a specific window's collection of properties, which allows those properties to be queried or set.
/// </summary>
/// <typeparam name="TIntf">The type of the property store object to retrieve. This is typically IPropertyStore.</typeparam>
/// <param name="hwnd"><para>Type: <c>HWND</c></para>
/// <para>A handle to the window whose properties are being retrieved.</para></param>
/// <returns>
/// When this function returns, contains the interface pointer requested in . This is typically IPropertyStore.
/// </returns>
/// <remarks>
/// <para>
/// An application can use this function to obtain access to a window's property store so that it can set an explicit Application
/// User Model ID (AppUserModelID) in the System.AppUserModel.ID property.
/// </para>
/// <para>
/// A window's properties must be removed before the window is closed. If this is not done, the resources used by those properties
/// are not returned to the system. A property is removed by setting it to the PROPVARIANT type VT_EMPTY.
/// </para>
/// <para>
/// When a call is made to IPropertyStore::SetValue on the object retrieved through , the properties and values are immediately
/// stored on the window. Therefore, no call to IPropertyStore::Commit is needed. No error occurs if it is called, but it has no effect.
/// </para>
/// <para>
/// An application sets AppUserModelIDs on individual windows to control the application's taskbar grouping and Jump List contents.
/// For instance, a suite application might want to provide a different taskbar button for each of its subfeatures, with the windows
/// relating to that subfeature grouped under that button. Without window-level AppUserModelIDs, those windows would all be grouped
/// together under the main process.
/// </para>
/// <para>
/// Applications should also use this property store to set these relaunch properties so that the system can return the application
/// to that state.
/// </para>
/// <list type="bullet">
/// <item>System.AppUserModel.RelaunchCommand</item>
/// <item>System.AppUserModel.RelaunchDisplayNameResource</item>
/// <item>System.AppUserModel.RelaunchIconResource</item>
/// </list>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shgetpropertystoreforwindow SHSTDAPI
// SHGetPropertyStoreForWindow( HWND hwnd, REFIID riid, void **ppv );
[PInvokeData("shellapi.h", MSDNShortId = "772aa2c8-6dd1-480c-a008-58f30902cb80")]
public static TIntf SHGetPropertyStoreForWindow<TIntf>(HWND hwnd) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHGetPropertyStoreForWindow(hwnd, g, out o));
/// <summary>
/// <para>Retrieves information about system-defined Shell icons.</para>
/// </summary>

View File

@ -3265,6 +3265,30 @@ namespace Vanara.PInvoke
[PInvokeData("shlobj_core.h", MSDNShortId = "72a79d1b-15ed-475e-9ebd-03345579a06a")]
public static extern HRESULT SHBindToFolderIDListParent(IShellFolder psfRoot, PIDL pidl, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv, out IntPtr ppidlLast);
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TIntf">The type of the requested interface. This is typically IShellFolder or IShellFolder2, but
/// can be anything supported by the target folder.</typeparam>
/// <param name="psfRoot"><para>Type: <c>IShellFolder*</c></para>
/// <para>A pointer to a Shell folder object. If is <c>NULL</c>, indicates that the IDList passed is relative to the desktop.</para></param>
/// <param name="pidl"><para>Type: <c>PCUIDLIST_RELATIVE</c></para>
/// <para>A PIDL to bind to, relative to . If is <c>NULL</c>, this is an absolute IDList relative to the desktop folder.</para></param>
/// <returns>
/// When this function returns, contains the interface pointer requested. This is typically IShellFolder or IShellFolder2, but
/// can be anything supported by the target folder.
/// </returns>
/// <remarks>
/// <c>Note</c> Calling the <c>SHBindToFolderIDListParent</c> function is equivalent to calling the SHBindToFolderIDListParentEx
/// function with <c>NULL</c> as the bind context.
/// </remarks>
// 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 );
[PInvokeData("shlobj_core.h", MSDNShortId = "72a79d1b-15ed-475e-9ebd-03345579a06a")]
public static TIntf SHBindToFolderIDListParent<TIntf>(IShellFolder psfRoot = null, PIDL pidl = null) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHBindToFolderIDListParent(psfRoot, pidl, g, out o, out var _));
/// <summary>
/// <para>Extends the SHBindToFolderIDListParent function by allowing the caller to specify a bind context.</para>
/// </summary>
@ -3315,54 +3339,103 @@ namespace Vanara.PInvoke
[PInvokeData("shlobj_core.h", MSDNShortId = "4f9b68cb-d0ae-45f7-90f5-2db1da3ab599")]
public static extern HRESULT SHBindToFolderIDListParentEx(IShellFolder psfRoot, PIDL pidl, IBindCtx ppbc, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv, out IntPtr ppidlLast);
/// <summary>
/// <para>Retrieves and binds to a specified object by using the Shell namespace IShellFolder::BindToObject method.</para>
/// </summary>
/// <param name="psf">
/// <summary>Extends the SHBindToFolderIDListParent function by allowing the caller to specify a bind context.</summary>
/// <typeparam name="TIntf">
/// The type of the requested interface. This is typically IShellFolder or IShellFolder2, but can be anything supported by the target folder.
/// </typeparam>
/// <param name="psfRoot">
/// <para>Type: <c>IShellFolder*</c></para>
/// <para>
/// A pointer to IShellFolder. This parameter can be <c>NULL</c>. If is <c>NULL</c>, this indicates parameter is relative to the
/// desktop. In this case, must specify an absolute ITEMIDLIST.
/// </para>
/// <para>A pointer to a Shell folder object. If is <c>NULL</c>, indicates that the IDList passed is relative to the desktop.</para>
/// </param>
/// <param name="pidl">
/// <para>Type: <c>PCUIDLIST_RELATIVE</c></para>
/// <para>
/// A pointer to a constant ITEMIDLIST to bind to that is relative to . If is <c>NULL</c>, this is an absolute <c>ITEMIDLIST</c>
/// relative to the desktop folder.
/// </para>
/// <para>A PIDL to bind to, relative to . If is <c>NULL</c>, this is an absolute IDList relative to the desktop folder.</para>
/// </param>
/// <param name="pbc">
/// <param name="ppbc">
/// <para>Type: <c>IBindCtx*</c></para>
/// <para>
/// 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 <c>NULL</c>. Because support for is optional for folder object implementations, some folders may not support the use of bind contexts.
/// to <c>NULL</c>, 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.
/// </para>
/// </param>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>Identifier of the interface to return.</para>
/// </param>
/// <param name="ppv">
/// <para>Type: <c>void**</c></para>
/// <returns>
/// 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.
/// </returns>
// 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 );
[PInvokeData("shlobj_core.h", MSDNShortId = "4f9b68cb-d0ae-45f7-90f5-2db1da3ab599")]
public static TIntf SHBindToFolderIDListParentEx<TIntf>(IShellFolder psfRoot = null, PIDL pidl = null, IBindCtx ppbc = null) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHBindToFolderIDListParentEx(psfRoot, pidl, ppbc, g, out o, out var _));
/// <summary>
/// Retrieves and binds to a specified object by using the Shell namespace IShellFolder::BindToObject method.
/// </summary>
/// <param name="psf"><para>Type: <c>IShellFolder*</c></para>
/// <para>
/// A pointer to IShellFolder. This parameter can be <c>NULL</c>. If is <c>NULL</c>, this indicates parameter is relative to the
/// desktop. In this case, must specify an absolute ITEMIDLIST.
/// </para></param>
/// <param name="pidl"><para>Type: <c>PCUIDLIST_RELATIVE</c></para>
/// <para>
/// A pointer to a constant ITEMIDLIST to bind to that is relative to . If is <c>NULL</c>, this is an absolute <c>ITEMIDLIST</c>
/// relative to the desktop folder.
/// </para></param>
/// <param name="pbc"><para>Type: <c>IBindCtx*</c></para>
/// <para>
/// 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 <c>NULL</c>. Because support for is optional for folder object implementations, some folders may not support the use of bind contexts.
/// </para></param>
/// <param name="riid"><para>Type: <c>REFIID</c></para>
/// <para>Identifier of the interface to return.</para></param>
/// <param name="ppv"><para>Type: <c>void**</c></para>
/// <para>
/// When this method returns, contains the interface pointer as specified in to the bound object. If an error occurs, contains a
/// <c>NULL</c> pointer.
/// </para>
/// </param>
/// </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><c>Note</c> This is a helper function that gets the desktop object by calling SHGetDesktopFolder.</para>
/// </remarks>
/// <remarks><c>Note</c> This is a helper function that gets the desktop object by calling SHGetDesktopFolder.</remarks>
// 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 Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
/// <summary>
/// Retrieves and binds to a specified object by using the Shell namespace IShellFolder::BindToObject method.
/// </summary>
/// <typeparam name="TIntf">Type of the interface to return.</typeparam>
/// <param name="psf"><para>Type: <c>IShellFolder*</c></para>
/// <para>
/// A pointer to IShellFolder. This parameter can be <c>NULL</c>. If is <c>NULL</c>, this indicates parameter is relative to the
/// desktop. In this case, must specify an absolute ITEMIDLIST.
/// </para></param>
/// <param name="pidl"><para>Type: <c>PCUIDLIST_RELATIVE</c></para>
/// <para>
/// A pointer to a constant ITEMIDLIST to bind to that is relative to . If is <c>NULL</c>, this is an absolute <c>ITEMIDLIST</c>
/// relative to the desktop folder.
/// </para></param>
/// <param name="pbc"><para>Type: <c>IBindCtx*</c></para>
/// <para>
/// 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 <c>NULL</c>. Because support for is optional for folder object implementations, some folders may not support the use of bind contexts.
/// </para></param>
/// <returns>
/// When this method returns, contains the interface pointer as specified in to the bound object. If an error occurs, contains a
/// <c>NULL</c> pointer.
/// </returns>
/// <remarks><c>Note</c> This is a helper function that gets the desktop object by calling SHGetDesktopFolder.</remarks>
// 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 );
[PInvokeData("shlobj_core.h", MSDNShortId = "acc16097-8301-4118-8cb5-00aa2705306a")]
public static TIntf SHBindToObject<TIntf>(IShellFolder psf, PIDL pidl, IBindCtx pbc) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHBindToObject(psf, pidl, pbc, g, out o));
/// <summary>
/// <para>
/// Takes a pointer to a fully qualified item identifier list (PIDL), and returns a specified interface pointer on the parent object.
@ -3401,6 +3474,19 @@ namespace Vanara.PInvoke
[PInvokeData("shlobj_core.h", MSDNShortId = "1cb283a6-3ebf-4986-9f32-5f6ab8d977ad")]
public static extern HRESULT SHBindToParent(PIDL pidl, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv, out IntPtr ppidlLast);
/// <summary>
/// Takes a pointer to a fully qualified item identifier list (PIDL), and returns a specified interface pointer on the parent object.
/// </summary>
/// <typeparam name="TIntf">The Type of one of the interfaces exposed by the item's parent object.</typeparam>
/// <param name="pidl"><para>Type: <c>PCIDLIST_ABSOLUTE</c></para>
/// <para>The item's PIDL.</para></param>
/// <returns>A pointer to the interface specified. You must release the object when you are finished.</returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shbindtoparent SHSTDAPI SHBindToParent(
// PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv, PCUITEMID_CHILD *ppidlLast );
[PInvokeData("shlobj_core.h", MSDNShortId = "1cb283a6-3ebf-4986-9f32-5f6ab8d977ad")]
public static TIntf SHBindToParent<TIntf>(PIDL pidl) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHBindToParent(pidl, g, out o, out var _));
/// <summary>Displays a dialog box that enables the user to select a Shell folder.</summary>
/// <param name="lpbi">A pointer to a BROWSEINFO structure that contains information used to display the dialog box.</param>
/// <returns>
@ -5017,6 +5103,34 @@ namespace Vanara.PInvoke
[PInvokeData("Shlobj.h", MSDNShortId = "dd378429")]
public static extern HRESULT SHGetKnownFolderItem(in Guid rfid, KNOWN_FOLDER_FLAG dwFlags, [In, Optional] HTOKEN hToken, in Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv);
/// <summary>Retrieves an IShellItem object that represents a known folder.</summary>
/// <typeparam name="TIntf">The Type of the interface that represents the item, usually IShellItem or IShellItem2.</typeparam>
/// <param name="rfid">The KNOWNFOLDERID that identifies the folder that contains the item.</param>
/// <param name="dwFlags">
/// Flags that specify special options used in the retrieval of the known folder IShellItem. This value can be KF_FLAG_DEFAULT;
/// otherwise, one or more of the KNOWN_FOLDER_FLAG values.
/// </param>
/// <param name="hToken">
/// An access token used to represent a particular user. This parameter is usually set to NULL, in which case the function tries to
/// access the current user's instance of the folder. However, you may need to assign a value to hToken for those folders that can
/// have multiple users but are treated as belonging to a single user. The most commonly used folder of this type is Documents.
/// <para>
/// The calling application is responsible for correct impersonation when hToken is non-null. It must have appropriate security
/// privileges for the particular user, including TOKEN_QUERY and TOKEN_IMPERSONATE, and the user's registry hive must be currently
/// mounted. See Access Control for further discussion of access control issues.
/// </para>
/// <para>
/// Assigning the hToken parameter a value of -1 indicates the Default User. This allows clients of SHGetKnownFolderIDList to find
/// folder locations (such as the Desktop folder) for the Default User. The Default User user profile is duplicated when any new user
/// account is created, and includes special folders such as Documents and Desktop. Any items added to the Default User folder also
/// appear in any new user account. Note that access to the Default User folders requires administrator privileges.
/// </para>
/// </param>
/// <returns>When this method returns, contains the interface pointer requested.</returns>
[PInvokeData("Shlobj.h", MSDNShortId = "dd378429")]
public static TIntf SHGetKnownFolderItem<TIntf>(KNOWNFOLDERID rfid, KNOWN_FOLDER_FLAG dwFlags = KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, [In] HTOKEN hToken = default) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => SHGetKnownFolderItem(rfid.Guid(), dwFlags, hToken, g, out o));
/// <summary>Retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID.</summary>
/// <param name="rfid">A reference to the KNOWNFOLDERID that identifies the folder.</param>
/// <param name="dwFlags">
@ -6167,6 +6281,26 @@ namespace Vanara.PInvoke
[PInvokeData("shlobj_core.h", MSDNShortId = "d45ec25c-359b-46f8-b0f6-5888525c7349")]
public static extern HRESULT StgMakeUniqueName(IStorage pstgParent, [MarshalAs(UnmanagedType.LPWStr)] string pszFileSpec, STGM grfMode, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
/// <summary>Creates a unique name for a stream or storage object from a template.</summary>
/// <typeparam name="TIntf">The type of the interface to retrieve through, typically IStorage or IStream.</typeparam>
/// <param name="pstgParent"><para>Type: <c>IStorage*</c></para>
/// <para>A pointer to an IStorage object.</para></param>
/// <param name="pszFileSpec"><para>Type: <c>PCWSTR</c></para>
/// <para>The format or template for the name of the stream or storage object.</para></param>
/// <param name="grfMode"><para>Type: <c>DWORD</c></para>
/// <para>
/// The access mode to use when opening the stream or storage object. For more information and descriptions of the possible values,
/// see STGM Constants.
/// </para></param>
/// <returns>
/// When this method returns, contains the interface pointer requested in . This is typically IStorage or IStream.
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-stgmakeuniquename HRESULT StgMakeUniqueName(
// IStorage *pstgParent, PCWSTR pszFileSpec, DWORD grfMode, REFIID riid, void **ppv );
[PInvokeData("shlobj_core.h", MSDNShortId = "d45ec25c-359b-46f8-b0f6-5888525c7349")]
public static TIntf StgMakeUniqueName<TIntf>(IStorage pstgParent, string pszFileSpec, STGM grfMode) where TIntf : class =>
IidGetObj<TIntf>((in Guid g, out object o) => StgMakeUniqueName(pstgParent, pszFileSpec, grfMode, g, out o));
/// <summary>
/// <para>
/// [Win32DeleteFile is available for use in the operating systems specified in the Requirements section. It may be altered or

View File

@ -1505,20 +1505,14 @@ namespace Vanara.PInvoke
public static extern HRESULT IStream_Copy(IStream pstmFrom, IStream pstmTo, uint cb);
/// <summary>
/// <para>Reads bytes from a specified stream and returns a value that indicates whether all bytes were successfully read.</para>
/// Reads bytes from a specified stream and returns a value that indicates whether all bytes were successfully read.
/// </summary>
/// <param name="pstm">
/// <para>Type: <c>IStream*</c></para>
/// <para>A pointer to the IStream interface of the stream from which to read.</para>
/// </param>
/// <param name="pv">
/// <para>Type: <c>VOID*</c></para>
/// <para>A pointer to a buffer to receive the stream data from pstm. This buffer must be at least cb bytes in size.</para>
/// </param>
/// <param name="cb">
/// <para>Type: <c>ULONG</c></para>
/// <para>The number of bytes of data that the function should attempt to read from the input stream.</para>
/// </param>
/// <param name="pstm"><para>Type: <c>IStream*</c></para>
/// <para>A pointer to the IStream interface of the stream from which to read.</para></param>
/// <param name="pv"><para>Type: <c>VOID*</c></para>
/// <para>A pointer to a buffer to receive the stream data from pstm. This buffer must be at least cb bytes in size.</para></param>
/// <param name="cb"><para>Type: <c>ULONG</c></para>
/// <para>The number of bytes of data that the function should attempt to read from the input stream.</para></param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>
@ -1527,17 +1521,41 @@ namespace Vanara.PInvoke
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// This function calls the ISequentialStream::Read method to read data from the specified stream into the buffer. If the function
/// fails for any reason, the contents of the output buffer and the position of the read pointer in the input stream are undefined.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_read LWSTDAPI IStream_Read( IStream *pstm, void
// *pv, ULONG cb );
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_read
// LWSTDAPI IStream_Read(IStream *pstm, void *pv, ULONG cb );
[DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("shlwapi.h", MSDNShortId = "07a3a500-babb-458b-ba98-9344c63ea014")]
public static extern HRESULT IStream_Read(IStream pstm, IntPtr pv, uint cb);
/// <summary>
/// Reads bytes from a specified stream and returns a value that indicates whether all bytes were successfully read.
/// </summary>
/// <param name="pstm"><para>Type: <c>IStream*</c></para>
/// <para>A pointer to the IStream interface of the stream from which to read.</para></param>
/// <param name="pv"><para>Type: <c>VOID*</c></para>
/// <para>A pointer to a buffer to receive the stream data from pstm. This buffer must be at least cb bytes in size.</para></param>
/// <param name="cb"><para>Type: <c>ULONG</c></para>
/// <para>The number of bytes of data that the function should attempt to read from the input stream.</para></param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>
/// Returns <c>S_OK</c> if the function successfully reads the specified number of bytes from the stream, or a COM failure code
/// otherwise. In particular, if the read attempt was successful but fewer than cb bytes were read, the function returns <c>E_FAIL</c>.
/// </para>
/// </returns>
/// <remarks>
/// This function calls the ISequentialStream::Read method to read data from the specified stream into the buffer. If the function
/// fails for any reason, the contents of the output buffer and the position of the read pointer in the input stream are undefined.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_read
// LWSTDAPI IStream_Read(IStream *pstm, void *pv, ULONG cb );
[DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("shlwapi.h", MSDNShortId = "07a3a500-babb-458b-ba98-9344c63ea014")]
public static extern HRESULT IStream_Read(IStream pstm, SafeAllocatedMemoryHandle pv, uint cb);
/// <summary>
/// <para>Reads a pointer to an item identifier list (PIDL) from an IStream object into a PIDLIST_RELATIVE object.</para>
/// </summary>
@ -1873,6 +1891,41 @@ namespace Vanara.PInvoke
[PInvokeData("shlwapi.h", MSDNShortId = "3e3f3ed0-ad36-40ef-b30c-8c85ff159f21")]
public static extern HRESULT IUnknown_QueryService([MarshalAs(UnmanagedType.IUnknown)] object punk, in Guid guidService, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 2)] out object ppvOut);
/// <summary>Retrieves an interface for a service from a specified object.</summary>
/// <typeparam name="TOut">The type of the desired service interface.</typeparam>
/// <param name="punk"><para>Type: <c>IUnknown*</c></para>
/// <para>A pointer to the IUnknown instance of the COM object that supports the service.</para></param>
/// <param name="guidService"><para>Type: <c>REFGUID</c></para>
/// <para>The service's unique identifier (SID).</para></param>
/// <param name="riid"><para>Type: <c>Guid?</c></para>
/// <para>The IID of the desired service interface. If <see langword="null" />, the Guid of the <typeparamref name="TOut" /> type is used.</para></param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>
/// When this method returns, contains the interface pointer requested riid. If successful, the calling application is responsible
/// for calling IUnknown::Release using this value when the service is no longer needed. In the case of failure, this value is <c>NULL</c>.
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// If the object passed in the punk parameter supports the IServiceProvider interface, then its QueryService method is invoked,
/// passing the guidService, riid, and ppvOut parameters and propagating the return value. Otherwise, the function returns E_FAIL.
/// </para>
/// <para>
/// For those versions of Windows that do not include <c>IUnknown_QueryService</c> in Shlwapi.h, this function must be called
/// directly from Shlwapi.dll using ordinal 176.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_queryservice LWSTDAPI IUnknown_QueryService(
// IUnknown *punk, REFGUID guidService, REFIID riid, void **ppvOut );
[PInvokeData("shlwapi.h", MSDNShortId = "3e3f3ed0-ad36-40ef-b30c-8c85ff159f21")]
public static TOut IUnknown_QueryService<TOut>(object punk, in Guid guidService, in Guid? riid = null)
{
var iid = riid ?? typeof(TOut).GUID;
IUnknown_QueryService(punk, guidService, iid, out var ppvOut).ThrowIfFailed();
return (TOut)ppvOut;
}
/// <summary>
/// <para>Changes the value of a Component Object Model (COM) interface pointer and releases the previous interface.</para>
/// </summary>