Added generic helper methods for all interface methods that get a COM interface by specifying its IID.

pull/30/head
David Hall 2019-01-06 11:57:14 -07:00
parent 9c7a434c75
commit 8623205679
17 changed files with 543 additions and 41 deletions

View File

@ -12,8 +12,10 @@ namespace Vanara.PInvoke
{
/// <summary>Replace current value.</summary>
PKA_SET = 0,
/// <summary>Append to current value - multi-value properties only.</summary>
PKA_APPEND = 1,
/// <summary>Delete from current value - multi-value properties only.</summary>
PKA_DELETE = 2
}
@ -25,7 +27,8 @@ namespace Vanara.PInvoke
{
/// <summary>Sets the property key.</summary>
/// <param name="key">The property key.</param>
void SetPropertyKey(ref PROPERTYKEY key);
void SetPropertyKey(in PROPERTYKEY key);
/// <summary>Gets the property key.</summary>
/// <returns>When this returns, contains the property key.</returns>
PROPERTYKEY GetPropertyKey();
@ -39,10 +42,12 @@ namespace Vanara.PInvoke
{
/// <summary>Sets the property key.</summary>
/// <param name="key">The property key.</param>
new void SetPropertyKey(ref PROPERTYKEY key);
new void SetPropertyKey(in PROPERTYKEY key);
/// <summary>Gets the property key.</summary>
/// <returns>When this returns, contains the property key.</returns>
new PROPERTYKEY GetPropertyKey();
/// <summary>Applies a change to a property value.</summary>
/// <param name="propvarIn">A reference to a source PROPVARIANT structure.</param>
/// <param name="ppropvarOut">A pointer to a changed PROPVARIANT structure.</param>
@ -57,35 +62,59 @@ namespace Vanara.PInvoke
/// <summary>Gets the number of change operations in the array.</summary>
/// <returns>The number of change operations.</returns>
uint GetCount();
/// <summary>Gets the change operation at a specified array index.</summary>
/// <param name="iIndex">The index of the change to retrieve.</param>
/// <param name="riid">A reference to the desired IID.</param>
/// <returns>The address of a pointer to the interface specified by riid, usually IPropertyChange.</returns>
[return: MarshalAs(UnmanagedType.Interface)]
object GetAt([In] uint iIndex, in Guid riid);
/// <summary>Inserts a change operation into an array at the specified position.</summary>
/// <param name="iIndex">The index at which the change is inserted.</param>
/// <param name="ppropChange">A pointer to the interface that contains the change.</param>
void InsertAt([In] uint iIndex, [In] IPropertyChange ppropChange);
/// <summary>Inserts a change operation at the end of an array.</summary>
/// <param name="ppropChange">A pointer to the interface that contains the change.</param>
void Append([In] IPropertyChange ppropChange);
/// <summary>Replaces the first occurrence of a change that affects the same property key as the provided change. If the property key is not already in the array, this method appends the change to the end of the array.</summary>
/// <summary>
/// Replaces the first occurrence of a change that affects the same property key as the provided change. If the property key is
/// not already in the array, this method appends the change to the end of the array.
/// </summary>
/// <param name="ppropChange">A pointer to the interface that contains the change.</param>
void AppendOrReplace([In] IPropertyChange ppropChange);
/// <summary>Removes a specified change.</summary>
/// <param name="iIndex">The index of the change to remove.</param>
void RemoveAt([In] uint iIndex);
/// <summary>Specifies whether a particular property key exists in the change array.</summary>
/// <param name="key">A reference to the PROPERTYKEY structure of interest.</param>
[PreserveSig] HRESULT IsKeyInArray(in PROPERTYKEY key);
}
/// <summary>Creates a container for a set of IPropertyChange objects. This container can be used with IFileOperation to apply a set of property changes to a set of files.</summary>
/// <param name="rgpropkey">Pointer to an array of PROPERTYKEY structures that name the specific properties whose changes are being stored. If this value is NULL, cChanges must be 0.</param>
/// <summary>Gets the change operation at a specified array index.</summary>
/// <typeparam name="T">The type of the interface to retrieve.</typeparam>
/// <param name="pca">The <see cref="IPropertyChangeArray"/> instance.</param>
/// <param name="iIndex">The index of the change to retrieve.</param>
/// <returns>The address of a pointer to the interface specified by <typeparamref name="T"/>, usually IPropertyChange.</returns>
public static T GetAt<T>(this IPropertyChangeArray pca, [In] uint iIndex) where T : class => (T)pca.GetAt(iIndex, typeof(T).GUID);
/// <summary>
/// Creates a container for a set of IPropertyChange objects. This container can be used with IFileOperation to apply a set of
/// property changes to a set of files.
/// </summary>
/// <param name="rgpropkey">
/// Pointer to an array of PROPERTYKEY structures that name the specific properties whose changes are being stored. If this value is
/// NULL, cChanges must be 0.
/// </param>
/// <param name="rgflags">Pointer to an array of PKA_FLAGS values. If this value is NULL, cChanges must be 0.</param>
/// <param name="rgpropvar">Pointer to an array of PROPVARIANT structures. If this value is NULL, cChanges must be 0.</param>
/// <param name="cChanges">Count of changes to be applied. This is the number of elements in each of the arrays rgpropkey, rgflags, and rgpropvar.</param>
/// <param name="cChanges">
/// Count of changes to be applied. This is the number of elements in each of the arrays rgpropkey, rgflags, and rgpropvar.
/// </param>
/// <param name="riid">Reference to the ID of the requested interface.</param>
/// <param name="ppv">When this function returns, contains the interface pointer requested in riid. This is typically IPropertyChangeArray.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
@ -109,4 +138,4 @@ namespace Vanara.PInvoke
public static extern HRESULT PSCreateSimplePropertyChange([In] PKA_FLAGS flags, in PROPERTYKEY key,
[In] PROPVARIANT propvar, in Guid riid, out IPropertyChange ppv);
}
}
}

View File

@ -327,13 +327,64 @@ namespace Vanara.PInvoke
[ComImport, Guid("75121952-e0d0-43e5-9380-1d80483acf72"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ICreateObject
{
/// <summary><para>Creates a local object of a specified class and returns a pointer to a specified interface on the object.</para></summary><param name="clsid"><para>Type: <c>REFCLSID</c></para><para>A reference to a CLSID.</para></param><param name="pUnkOuter"><para>Type: <c>IUnknown*</c></para><para>A pointer to the IUnknown interface that aggregates the object created by this function, or <c>NULL</c> if no aggregation is desired.</para></param><param name="riid"><para>Type: <c>REFIID</c></para><para>A reference to the IID of the interface the created object should return.</para></param><param name="ppv"><para>Type: <c>void**</c></para><para>When this method returns, contains the address of the pointer to the interface requested in riid.</para></param><returns><para>Type: <c>HRESULT</c></para><para>If this method succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para></returns><remarks><para>This method can be used with GetPropertyStoreWithCreateObject.</para></remarks>
/// <summary>
/// <para>Creates a local object of a specified class and returns a pointer to a specified interface on the object.</para>
/// </summary>
/// <param name="clsid">
/// <para>Type: <c>REFCLSID</c></para>
/// <para>A reference to a CLSID.</para>
/// </param>
/// <param name="pUnkOuter">
/// <para>Type: <c>IUnknown*</c></para>
/// <para>
/// A pointer to the IUnknown interface that aggregates the object created by this function, or <c>NULL</c> if no aggregation is desired.
/// </para>
/// </param>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>A reference to the IID of the interface the created object should return.</para>
/// </param>
/// <param name="ppv">
/// <para>Type: <c>void**</c></para>
/// <para>When this method returns, contains the address of the pointer to the interface requested in riid.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HRESULT</c></para>
/// <para>If this method succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
/// <remarks>
/// <para>This method can be used with GetPropertyStoreWithCreateObject.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/propsys/nf-propsys-icreateobject-createobject
// HRESULT CreateObject( REFCLSID clsid, IUnknown *pUnkOuter, REFIID riid, void **ppv );
[PInvokeData("propsys.h", MSDNShortId = "72c56de7-4c04-4bcf-b6bb-6e41d12b68a3")]
void CreateObject(in Guid clsid, [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, in Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv);
}
/// <summary>
/// Creates a local object of a specified class and returns a pointer to a specified interface on the object.
/// </summary>
/// <typeparam name="T">The type of the interface the created object should return.</typeparam>
/// <param name="co">The <see cref="ICreateObject"/> instance.</param>
/// <param name="clsid"><para>Type: <c>REFCLSID</c></para>
/// <para>A reference to a CLSID.</para></param>
/// <param name="pUnkOuter"><para>Type: <c>IUnknown*</c></para>
/// <para>
/// A pointer to the IUnknown interface that aggregates the object created by this function, or <c>NULL</c> if no aggregation is desired.
/// </para></param>
/// <returns>
/// <para>Type: <c>void**</c></para>
/// <para>When this method returns, contains the address of the pointer to the interface requested in riid.</para>
/// </returns>
/// <remarks>This method can be used with GetPropertyStoreWithCreateObject.</remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/propsys/nf-propsys-icreateobject-createobject
// HRESULT CreateObject( REFCLSID clsid, IUnknown *pUnkOuter, REFIID riid, void **ppv );
public static T CreateObject<T>(this ICreateObject co, in Guid clsid, [In, MarshalAs(UnmanagedType.IUnknown), Optional] object pUnkOuter) where T : class
{
co.CreateObject(clsid, pUnkOuter, typeof(T).GUID, out var ppv);
return (T)ppv;
}
/// <summary><para>Exposes a method to create a specified IPropertyStore object in circumstances where property access is potentially slow.</para></summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/propsys/nn-propsys-idelayedpropertystorefactory
[PInvokeData("propsys.h", MSDNShortId = "855c9f10-9f40-4c60-a669-551fa51133f5")]
@ -600,15 +651,26 @@ namespace Vanara.PInvoke
[PreserveSig] HRESULT GetImageReference([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszImageRes);
}
/// <summary>Exposes methods that enumerate the possible values for a property.</summary>
[ComImport, Guid("A99400F4-3D84-4557-94BA-1242FB2CC9A6"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[PInvokeData("Propsys.h")]
public interface IPropertyEnumTypeList
{
/// <summary>Gets the number of elements in the list.</summary>
/// <returns>The number of list elements.</returns>
uint GetCount();
/// <summary>Gets the IPropertyEnumType object at the specified index in the list.</summary>
/// <param name="itype">The index of the object in the list.</param>
/// <param name="riid">The IID of IPropertyEnumType</param>
/// <returns>An IPropertyEnumType instance.</returns>
[return: MarshalAs(UnmanagedType.Interface)]
IPropertyEnumType GetAt([In] uint itype, in Guid riid);
/// <summary>Gets the condition at the specified index.</summary>
/// <param name="index">Index of the desired condition.</param>
/// <param name="riid">A reference to the IID of the interface to retrieve.</param>
/// <returns>An ICondition interface pointer.</returns>
[return: MarshalAs(UnmanagedType.Interface)]
object GetConditionAt([In] uint index, in Guid riid);
@ -654,9 +716,11 @@ namespace Vanara.PInvoke
in Guid riid, out IPropertyStore ppv);
}
/// <summary><para>Exposes methods that get property descriptions, register and unregister property schemas, enumerate property descriptions, and format property values in a type-strict way.</para></summary><remarks><para>Many of the exported APIs (such as PSGetPropertyDescription) are simply wrappers around the IPropertySystem methods. If your code calls a lot of these helper APIs in sequence, it may be worthwhile to instantiate a single <c>IPropertySystem</c> object, and call the methods directly, rather than calling the helper APIs. (To improve the performance, the helper APIs do obtain a cached instance of the <c>IPropertySystem</c> object.)</para></remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/propsys/nn-propsys-ipropertysystem
[PInvokeData("propsys.h", MSDNShortId = "9ead94d9-4d4e-44c6-8c53-11c4c4ee2fb2")]
[SuppressUnmanagedCodeSecurity]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("ca724e8a-c3e6-442b-88a4-6fb0db8035a3")]
[PInvokeData("PropSys.h")]
public interface IPropertySystem
{
[return: MarshalAs(UnmanagedType.Interface)]

View File

@ -74,5 +74,12 @@ namespace Vanara.PInvoke
/// <summary>Removes all objects from the collection.</summary>
void Clear();
}
/// <summary>Extension method to simplify using the <see cref="IObjectArray.GetAt(uint, in Guid)"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="a">An <see cref="IObjectArray"/> instance.</param>
/// <param name="uiIndex">The index of the object</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetAt<T>(this IObjectArray a, uint uiIndex) where T : class => (T)a.GetAt(uiIndex, typeof(T).GUID);
}
}

View File

@ -239,8 +239,8 @@ namespace Vanara.PInvoke
/// <summary>Gets an interface for the current view of the browser.</summary>
/// <param name="riid">A reference to the desired interface ID.</param>
/// <returns>
/// When this method returns, contains the interface pointer requested in riid. This will typically be IShellView, IShellView2,
/// IFolderView, or a related interface.
/// When this method returns, contains the interface pointer requested in <paramref name="riid"/>. This will typically be
/// IShellView, IShellView2, IFolderView, or a related interface.
/// </returns>
[return: MarshalAs(UnmanagedType.Interface, IidParameterIndex = 0)]
object GetCurrentView(in Guid riid);
@ -272,6 +272,12 @@ namespace Vanara.PInvoke
HRESULT OnNavigationFailed([In] IntPtr pidlFolder);
}
/// <summary>Extension method to simplify using the <see cref="IExplorerBrowser.GetCurrentView"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="eb">An <see cref="IExplorerBrowser"/> instance.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetCurrentView<T>(this IExplorerBrowser eb) where T : class => (T)eb.GetCurrentView(typeof(T).GUID);
/// <summary>The ExplorerBrowser class is the base CoClass for all I ExplorerBrowser interfaces.</summary>
[ComImport, Guid("71f96385-ddd6-48d3-a0c1-ae06e8b055fb"), ClassInterface(ClassInterfaceType.None)]
[PInvokeData("Shobjidl.h", MSDNShortId = "da2cf5d4-5a68-4d18-807b-b9d4e2712c10")]

View File

@ -629,13 +629,14 @@ namespace Vanara.PInvoke
/// <para>Type: <c>REFIID</c></para>
/// <para>Reference to the desired IID to represent the item, such as IID_IShellItem.</para>
/// </param>
/// <param name="ppv">
/// <returns>
/// <para>Type: <c>void**</c></para>
/// <para>When this method returns, contains the interface pointer requested in <paramref name="riid"/>. This is typically IShellItem.</para>
/// </param>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getitem HRESULT GetItem( int
// iItem, REFIID riid, void **ppv );
void GetItem(int iItem, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetItem(int iItem, in Guid riid);
/// <summary>Gets the next visible item in relation to a given index in the view.</summary>
/// <param name="iStart">
@ -891,6 +892,29 @@ namespace Vanara.PInvoke
void RemoveAll();
}
/// <summary>Extension method to simplify using the <see cref="IFolderView.GetFolder"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="fv">An <see cref="IFolderView"/> instance.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetFolder<T>(this IFolderView fv) where T : class => (T)fv.GetFolder(typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IFolderView2.GetItem"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="fv">An <see cref="IFolderView2"/> instance.</param>
/// <param name="iItem">
/// <para>Type: <c>int</c></para>
/// <para>The zero-based index of the item to retrieve.</para>
/// </param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetItem<T>(this IFolderView2 fv, int iItem) where T : class => (T)fv.GetItem(iItem, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IFolderView.Items"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="fv">An <see cref="IFolderView"/> instance.</param>
/// <param name="uFlags">_SVGIO values that limit the enumeration to certain types of items.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T Items<T>(this IFolderView fv, SVGIO uFlags) where T : class => (T)fv.Items(uFlags, typeof(T).GUID);
/// <summary>
/// <para>Defines column information. Used by members of the IColumnManager interface.</para>
/// </summary>

View File

@ -372,7 +372,7 @@ namespace Vanara.PInvoke
[KnownFolderDetail("{D9DC8A3B-B784-432E-A781-5A1130A75963}", Equivalent = Environment.SpecialFolder.History)]
FOLDERID_History,
/// <summary>Homegroup</summary>
/// <summary>HomeGroup</summary>
[KnownFolderDetail("{52528A6B-B9E3-4ADD-B60D-588C2DBA842D}")]
FOLDERID_HomeGroup,
@ -601,7 +601,7 @@ namespace Vanara.PInvoke
FOLDERID_SavedPicturesLibrary,
/// <summary>Searches</summary>
[KnownFolderDetail("{7d1d3a04-debb-4115-95cf-2f29da2920da}")]
[KnownFolderDetail("{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}")]
FOLDERID_SavedSearches,
/// <summary>Screenshots</summary>
@ -727,7 +727,7 @@ namespace Vanara.PInvoke
/// <summary>
/// Exposes methods that allow an application to retrieve information about a known folder's category, type, GUID, pointer to an item
/// identifier list (PIDL) value, redirection capabilities, and definition. It provides a method for the retrival of a known folder's
/// identifier list (PIDL) value, redirection capabilities, and definition. It provides a method for the retrieval of a known folder's
/// IShellItem object. It also provides methods to get or set the path of the known folder.
/// </summary>
[ComImport, Guid("3AA7AF7E-9B36-420c-A8E3-F77D4674A488"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
@ -752,10 +752,10 @@ namespace Vanara.PInvoke
/// </param>
/// <param name="riid">A reference to the IID of the requested interface.</param>
/// <returns>
/// When this method returns, contains the interface pointer requested in riid. This is typically IShellItem or IShellItem2.
/// When this method returns, contains the interface pointer requested in <paramref name="riid"/>. This is typically IShellItem or IShellItem2.
/// </returns>
[return: MarshalAs(UnmanagedType.Interface)]
IShellItem GetShellItem([In] KNOWN_FOLDER_FLAG dwFlags, in Guid riid);
object GetShellItem([In] KNOWN_FOLDER_FLAG dwFlags, in Guid riid);
/// <summary>Retrieves the path of a known folder as a string.</summary>
/// <param name="dwFlags">
@ -927,8 +927,8 @@ namespace Vanara.PInvoke
/// </param>
/// <param name="cFolders">The number of KNOWNFOLDERID values in the array at pExclusion.</param>
/// <param name="pExclusion">
/// Pointer to an array of KNOWNFOLDERID values that refer to subfolders of rfid that should be excluded from the redirection. If
/// no subfolders are excluded, this value can be NULL.
/// Pointer to an array of KNOWNFOLDERID values that refer to subfolders of <paramref name="rfid"/> that should be excluded from
/// the redirection. If no subfolders are excluded, this value can be NULL.
/// </param>
/// <returns>
/// When this method returns, contains the address of a pointer to a null-terminated Unicode string that contains an error
@ -938,6 +938,15 @@ namespace Vanara.PInvoke
[In, MarshalAs(UnmanagedType.LPWStr)] string pszTargetPath, [In] uint cFolders, [In] Guid[] pExclusion);
}
/// <summary>Extension method to simplify using the <see cref="IKnownFolder.GetShellItem"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="fv">An <see cref="IKnownFolder"/> instance.</param>
/// <param name="dwFlags">
/// Flags that specify special retrieval options. This value can be 0; otherwise, one or more of the KNOWN_FOLDER_FLAG values.
/// </param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetShellItem<T>(this IKnownFolder fv, [In] KNOWN_FOLDER_FLAG dwFlags) where T : class => (T)fv.GetShellItem(dwFlags, typeof(T).GUID);
/// <summary>Defines the specifics of a known folder.</summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb773325")]

View File

@ -205,5 +205,11 @@ namespace Vanara.PInvoke
[PreserveSig]
HRESULT GetSite(in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppvSite);
}
/// <summary>Extension method to simplify using the <see cref="IObjectWithSite.GetSite"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="ows">An <see cref="IObjectWithSite"/> instance.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetSite<T>(this IObjectWithSite ows) where T : class { ows.GetSite(typeof(T).GUID, out var pSite).ThrowIfFailed(); return (T)pSite; }
}
}

View File

@ -192,6 +192,12 @@ namespace Vanara.PInvoke
PIDL GetIDList();
}
/// <summary>Extension method to simplify using the <see cref="ISearchFolderItemFactory.GetShellItem"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sfif">An <see cref="ISearchFolderItemFactory"/> instance.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetShellItem<T>(this ISearchFolderItemFactory sfif) where T : class => (T)sfif.GetShellItem(typeof(T).GUID);
/// <summary>CLSID_SearchFolderItemFactory</summary>
[PInvokeData("shobjidl_core.h", MSDNShortId = "a684b373-6de4-4b4a-bbae-85e1c5a7e04a")]
[ComImport, Guid("14010e02-bbbd-41f0-88e3-eda371216584"), ClassInterface(ClassInterfaceType.None)]

View File

@ -683,6 +683,64 @@ namespace Vanara.PInvoke
PROPERTYKEY MapColumnToSCID(uint iColumn);
}
/// <summary>Extension method to simplify using the <see cref="IShellFolder.BindToObject"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sf">An <see cref="IShellFolder"/> instance.</param>
/// <param name="pidl">
/// The address of an ITEMIDLIST structure (PIDL) that identifies the subfolder. This value can refer to an item at any level below
/// the parent folder in the namespace hierarchy. The structure contains one or more SHITEMID structures, followed by a terminating NULL.
/// </param>
/// <param name="pbc">
/// A pointer to an IBindCtx interface on a bind context object that can be used to pass parameters to the construction of the
/// handler. If this parameter is not used, set it to NULL. Because support for this parameter is optional for folder object
/// implementations, some folders may not support the use of bind contexts.
/// <para>
/// Information that can be provided in the bind context includes a BIND_OPTS structure that includes a grfMode member that indicates
/// the access mode when binding to a stream handler. Other parameters can be set and discovered using IBindCtx::RegisterObjectParam
/// and IBindCtx::GetObjectParam.
/// </para>
/// </param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T BindToObject<T>(this IShellFolder sf, [In] PIDL pidl, [In, Optional] IBindCtx pbc) where T : class => (T)sf.BindToObject(pidl, pbc, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IShellFolder.BindToStorage"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sf">An <see cref="IShellFolder"/> instance.</param>
/// <param name="pidl">
/// The address of an ITEMIDLIST structure that identifies the subfolder relative to its parent folder. The structure must contain
/// exactly one SHITEMID structure followed by a terminating zero.
/// </param>
/// <param name="pbc">
/// The optional address of an IBindCtx interface on a bind context object to be used during this operation. If this parameter is not
/// used, set it to NULL. Because support for pbc is optional for folder object implementations, some folders may not support the use
/// of bind contexts.
/// </param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T BindToStorage<T>(this IShellFolder sf, [In] PIDL pidl, [In, Optional] IBindCtx pbc) where T : class => (T)sf.BindToStorage(pidl, pbc, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IShellFolder.CreateViewObject"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sf">An <see cref="IShellFolder"/> instance.</param>
/// <param name="hwndOwner">
/// A handle to the owner window. If you have implemented a custom folder view object, your folder view window should be created as a
/// child of hwndOwner.
/// </param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T CreateViewObject<T>(this IShellFolder sf, HWND hwndOwner) where T : class => (T)sf.CreateViewObject(hwndOwner, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IShellFolder.GetUIObjectOf"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sf">An <see cref="IShellFolder"/> instance.</param>
/// <param name="hwndOwner">
/// A handle to the owner window that the client should specify if it displays a dialog box or message box.
/// </param>
/// <param name="apidl">
/// An array of pointers to ITEMIDLIST structures, each of which uniquely identifies a file object or subfolder relative to the
/// parent folder. Each item identifier list must contain exactly one SHITEMID structure followed by a terminating zero.
/// </param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetUIObjectOf<T>(this IShellFolder sf, HWND hwndOwner, PIDL[] apidl) where T : class => (T)sf.GetUIObjectOf(hwndOwner, (uint)apidl.Length, Array.ConvertAll(apidl, p => p.DangerousGetHandle()), typeof(T).GUID);
/// <summary>
/// Used by an IEnumExtraSearch enumerator object to return information on the search objects supported by a Shell Folder object.
/// </summary>

View File

@ -745,5 +745,43 @@ namespace Vanara.PInvoke
[PreserveSig]
HRESULT GetImage([In, MarshalAs(UnmanagedType.Struct)] SIZE size, [In] SIIGBF flags, out Gdi32.SafeHBITMAP phbm);
}
/// <summary>Extension method to simplify using the <see cref="IShellItem.BindToHandler"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="si">An <see cref="IShellItem"/> instance.</param>
/// <param name="pbc">
/// A pointer to an IBindCtx interface on a bind context object. Used to pass optional parameters to the handler. The contents of
/// the bind context are handler-specific. For example, when binding to BHID_Stream, the STGM flags in the bind context indicate
/// the mode of access desired (read or read/write).
/// </param>
/// <param name="bhid">Reference to a GUID that specifies which handler will be created.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T BindToHandler<T>(this IShellItem si, [In] IBindCtx pbc, in Guid bhid) where T : class => (T)si.BindToHandler(pbc, bhid, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IShellItemArray.BindToHandler"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sia">An <see cref="IShellItemArray"/> instance.</param>
/// <param name="pbc">
/// A pointer to an IBindCtx interface on a bind context object. Used to pass optional parameters to the handler. The contents of
/// the bind context are handler-specific. For example, when binding to BHID_Stream, the STGM flags in the bind context indicate
/// the mode of access desired (read or read/write).
/// </param>
/// <param name="rbhid">Reference to a GUID that specifies which handler will be created.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T BindToHandler<T>(this IShellItemArray sia, [In] IBindCtx pbc, in Guid rbhid) where T : class => (T)sia.BindToHandler(pbc, rbhid, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IShellItemArray.GetPropertyStore"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sia">An <see cref="IShellItemArray"/> instance.</param>
/// <param name="flags">One of the GETPROPERTYSTOREFLAGS constants.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetPropertyStore<T>(this IShellItemArray sia, GETPROPERTYSTOREFLAGS flags) where T : class => (T)sia.GetPropertyStore(flags, typeof(T).GUID);
/// <summary>Extension method to simplify using the <see cref="IShellItemArray.GetPropertyDescriptionList"/> method.</summary>
/// <typeparam name="T">Type of the interface to get.</typeparam>
/// <param name="sia">An <see cref="IShellItemArray"/> instance.</param>
/// <param name="keyType">A reference to the PROPERTYKEY structure specifying which property list to retrieve.</param>
/// <returns>Receives the interface pointer requested in <typeparamref name="T"/>.</returns>
public static T GetPropertyDescriptionList<T>(this IShellItemArray sia, in PROPERTYKEY keyType) where T : class => (T)sia.GetPropertyDescriptionList(keyType, typeof(T).GUID);
}
}

View File

@ -105,7 +105,7 @@ namespace Vanara.PInvoke
/// </param>
/// <returns>A pointer to the interface requested in riid. If this call fails, this value is NULL.</returns>
[return: MarshalAs(UnmanagedType.Interface)]
IShellItemArray GetFolders([In] LIBRARYFOLDERFILTER lff, in Guid riid);
object GetFolders([In] LIBRARYFOLDERFILTER lff, in Guid riid);
/// <summary>Resolves the target location of a library folder, even if the folder has been moved or renamed.</summary>
/// <param name="folderToResolve">An IShellItem object that represents the library folder to locate.</param>
@ -119,7 +119,7 @@ namespace Vanara.PInvoke
/// </param>
/// <returns>A pointer to the interface requested in riid.</returns>
[return: MarshalAs(UnmanagedType.Interface)]
IShellItem ResolveFolder([In] IShellItem folderToResolve, [In] uint timeout, in Guid riid);
object ResolveFolder([In] IShellItem folderToResolve, [In] uint timeout, in Guid riid);
/// <summary>Retrieves the default target folder that the library uses for save operations.</summary>
/// <param name="dsft">The DEFAULTSAVEFOLDERTYPE value that specifies the save folder to get.</param>
@ -129,7 +129,7 @@ namespace Vanara.PInvoke
/// </param>
/// <returns>A pointer to the interface requested in riid.</returns>
[return: MarshalAs(UnmanagedType.Interface)]
IShellItem GetDefaultSaveFolder([In] DEFAULTSAVEFOLDERTYPE dsft, in Guid riid);
object GetDefaultSaveFolder([In] DEFAULTSAVEFOLDERTYPE dsft, in Guid riid);
/// <summary>Sets the default target folder that the library will use for save operations.</summary>
/// <param name="dsft">The DEFAULTSAVEFOLDERTYPE value that specifies the default save location to set.</param>
@ -210,6 +210,31 @@ namespace Vanara.PInvoke
IShellItem SaveInKnownFolder(in Guid kfidToSaveIn, [In, MarshalAs(UnmanagedType.LPWStr)] string libraryName, [In] LIBRARYSAVEFLAGS lsf);
}
/// <summary>Retrieves the default target folder that the library uses for save operations.</summary>
/// <typeparam name="T">The type of the interface to get.</typeparam>
/// <param name="sl">The <see cref="IShellLibrary"/> instance.</param>
/// <param name="dsft">The DEFAULTSAVEFOLDERTYPE value that specifies the save folder to get.</param>
/// <returns>A pointer to the interface requested.</returns>
public static T GetDefaultSaveFolder<T>(this IShellLibrary sl, [In] DEFAULTSAVEFOLDERTYPE dsft) where T : class => (T)sl.GetDefaultSaveFolder(dsft, typeof(T).GUID);
/// <summary>Gets the set of child folders that are contained in the library.</summary>
/// <typeparam name="T">The type of the interface to get.</typeparam>
/// <param name="sl">The <see cref="IShellLibrary"/> instance.</param>
/// <param name="lff">One of the following LIBRARYFOLDERFILTER values that determines the folders to get.</param>
/// <returns>A pointer to the interface requested. If this call fails, this value is NULL.</returns>
public static T GetFolders<T>(this IShellLibrary sl, [In] LIBRARYFOLDERFILTER lff) where T : class => (T)sl.GetFolders(lff, typeof(T).GUID);
/// <summary>Resolves the target location of a library folder, even if the folder has been moved or renamed.</summary>
/// <typeparam name="T">The type of the interface to get.</typeparam>
/// <param name="sl">The <see cref="IShellLibrary"/> instance.</param>
/// <param name="folderToResolve">An IShellItem object that represents the library folder to locate.</param>
/// <param name="timeout">
/// The maximum time, in milliseconds, the method will attempt to locate the folder before returning. If the folder could not be
/// located before the specified time elapses, an error is returned.
/// </param>
/// <returns>A pointer to the interface requested.</returns>
public static T ResolveFolder<T>(this IShellLibrary sl, [In] IShellItem folderToResolve, [In] uint timeout) where T : class => (T)sl.ResolveFolder(folderToResolve, timeout, typeof(T).GUID);
/// <summary>Resolves all locations in a library, even those locations that have been moved or renamed.</summary>
/// <param name="psiLibrary">A pointer to an IShellItem object that represents the library.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>

View File

@ -1108,6 +1108,15 @@ namespace Vanara.PInvoke
FOLDERFLAGS dwFlags, FOLDERVIEWMODE fvMode, in Guid pvid, in RECT prcView);
}
/// <summary>Gets an interface that refers to data presented in the view.</summary>
/// <typeparam name="T">The type of the COM interface being requested.</typeparam>
/// <param name="sv">The <see cref="IShellView"/> instance.</param>
/// <param name="uItem">The constants that refer to an aspect of the view.</param>
/// <returns>
/// The address that receives the interface pointer. If an error occurs, the pointer returned must be NULL.
/// </returns>
public static T GetItemObject<T>(this IShellView sv, SVGIO uItem) where T : class => (T)sv.GetItemObject(uItem, typeof(T).GUID);
/// <summary>Contains folder view information.</summary>
[PInvokeData("Shobjidl.h")]
[StructLayout(LayoutKind.Sequential)]

View File

@ -773,6 +773,44 @@ namespace Vanara.PInvoke
void SetTabProperties(HWND hwndTab, STPFLAG stpFlags);
}
/// <summary>Initiates a building session for a custom Jump List.</summary>
/// <typeparam name="T">
/// A type of an interface to be retrieved, typically IID_IObjectArray, that will represent all items currently stored in the list of
/// removed destinations for the application. This information is used to ensure that removed items are not part of the new Jump List.
/// </typeparam>
/// <param name="cdl">The <see cref="ICustomDestinationList"/> instance.</param>
/// <param name="pcMaxSlots">
/// A pointer that, when this method returns, points to the current user setting for the Number of recent items to display in Jump
/// Lists option in the Taskbar and Start Menu Properties window. The default value is 10. This is the maximum number of destinations
/// that will be shown, and it is a total of all destinations, regardless of category. More destinations can be added, but they will
/// not be shown in the UI.
/// <para>A Jump List will always show at least this many slots—destinations and, if there is room, tasks.</para>
/// <para>
/// This number does not include separators and section headers as long as the total number of separators and headers does not exceed
/// four. Separators and section headers beyond the first four might reduce the number of destinations displayed if space is
/// constrained. This number does not affect the standard command entries for pinning or unpinning, closing the window, or launching
/// a new instance. It also does not affect tasks or pinned items, the number of which that can be displayed is based on the space
/// available to the Jump List.
/// </para>
/// </param>
/// <returns>
/// When this method returns, contains the interface pointer requested. This is typically an IObjectArray, which represents a
/// collection of IShellItem and IShellLink objects that represent the removed items.
/// </returns>
public static T BeginList<T>(this ICustomDestinationList cdl, out uint pcMaxSlots) where T : class => (T)cdl.BeginList(out pcMaxSlots, typeof(T).GUID);
/// <summary>
/// Retrieves the current list of destinations that have been removed by the user from the existing Jump List that this custom Jump
/// List is meant to replace.
/// </summary>
/// <typeparam name="T">The type of the interface to retrieve, typically IID_IObjectArray.</typeparam>
/// <param name="cdl">The <see cref="ICustomDestinationList"/> instance.</param>
/// <returns>
/// When this method returns, contains the interface pointer requested. This is typically an IObjectArray, which represents a
/// collection of IShellItem or IShellLink objects that represent the items in the list of removed destinations.
/// </returns>
public static T GetRemovedDestinations<T>(this ICustomDestinationList cdl) where T : class => (T)cdl.GetRemovedDestinations(typeof(T).GUID);
/// <summary>
/// Used by methods of the ITaskbarList3 interface to define buttons used in a toolbar embedded in a window's thumbnail representation.
/// </summary>

View File

@ -394,8 +394,8 @@ namespace Vanara.PInvoke
/// <param name="pstReferenceTime">
/// <para>Type: <c>SYSTEMTIME const*</c></para>
/// <para>
/// A pointer to a <c>SYSTEMTIME</c> value to use as the reference date and time. A null pointer can be passed if
/// <paramref name="sqro"/> is set to SQRO_DONT_RESOLVE_DATETIME.
/// A pointer to a <c>SYSTEMTIME</c> value to use as the reference date and time. A null pointer can be passed if <paramref
/// name="sqro"/> is set to SQRO_DONT_RESOLVE_DATETIME.
/// </para>
/// </param>
/// <returns>
@ -509,8 +509,7 @@ namespace Vanara.PInvoke
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nf-structuredquery-ientity-getrelationship HRESULT
// GetRelationship( LPCWSTR pszRelationName, IRelationship **pRelationship );
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetRelationship([In, MarshalAs(UnmanagedType.LPWStr)] string pszRelationName);
IRelationship GetRelationship([In, MarshalAs(UnmanagedType.LPWStr)] string pszRelationName);
/// <summary>
/// <para>Retrieves an enumeration of IMetaData objects for this entity.</para>
@ -1024,8 +1023,8 @@ namespace Vanara.PInvoke
/// <param name="pstReferenceTime">
/// <para>Type: <c>SYSTEMTIME const*</c></para>
/// <para>
/// A pointer to a <c>SYSTEMTIME</c> value to use as the reference date and time. A null pointer can be passed if
/// <paramref name="sqro"/> is set to SQRO_DONT_RESOLVE_DATETIME.
/// A pointer to a <c>SYSTEMTIME</c> value to use as the reference date and time. A null pointer can be passed if <paramref
/// name="sqro"/> is set to SQRO_DONT_RESOLVE_DATETIME.
/// </para>
/// </param>
/// <returns>
@ -1128,6 +1127,80 @@ namespace Vanara.PInvoke
[Out, MarshalAs(UnmanagedType.IUnknown)] out object ppWordBreaker);
}
/// <summary>Provides methods for retrieving information about a schema property.</summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nn-structuredquery-irelationship
[PInvokeData("structuredquery.h")]
[ComImport, Guid("2769280B-5108-498c-9C7F-A51239B63147"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IRelationship
{
/// <summary>Retrieves the name of the relationship.</summary>
/// <returns>
/// <para>Type: <c>LPWSTR*</c></para>
/// <para>
/// Receives a pointer to the name of the relationship as a Unicode string. The calling application must free the returned string
/// by calling CoTaskMemFree.
/// </para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nf-structuredquery-irelationship-name HRESULT Name(
// LPWSTR *ppszName );
[return: MarshalAs(UnmanagedType.LPWStr)]
string Name();
/// <summary>Reports whether a relationship is real.</summary>
/// <returns>
/// <para>Type: <c>BOOL*</c></para>
/// <para>Receives <c>TRUE</c> for a real relationship; otherwise, <c>FALSE</c>.</para>
/// </returns>
/// <remarks>
/// A relationship is not considered real if its source entity derives from an entity that has a relationship of the same name.
/// The purpose of such a "shadow" relationship is to store metadata specific to the inherited relationship.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nf-structuredquery-irelationship-isreal HRESULT IsReal(
// BOOL *pIsReal );
[return: MarshalAs(UnmanagedType.Bool)]
bool IsReal();
/// <summary>
/// Retrieves the destination IEntity object of the relationship. The destination of a relationship corresponds to the type of a property.
/// </summary>
/// <returns>
/// <para>Type: <c>IEntity**</c></para>
/// <para>
/// Receives the address of a pointer to an IEntity object, or <c>NULL</c> if the relationship is not real. For more information,
/// see IRelationship::IsReal.
/// </para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nf-structuredquery-irelationship-destination HRESULT
// Destination( IEntity **pDestinationEntity );
IEntity Destination();
/// <summary>Retrieves an enumeration of IMetaData objects for this relationship.</summary>
/// <param name="riid">
/// <para>Type: <c>REFIID</c></para>
/// <para>The desired IID of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</para>
/// </param>
/// <returns>
/// <para>Type: <c>void**</c></para>
/// <para>
/// Receives a pointer to the enumeration of IMetaData objects. There may be multiple pairs with the same key (or the same value).
/// </para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nf-structuredquery-irelationship-metadata HRESULT
// MetaData( REFIID riid, void **pMetaData );
[return: MarshalAs(UnmanagedType.IUnknown)]
object MetaData(in Guid riid);
/// <summary>Retrieves the default phrase to use for this relationship in restatements.</summary>
/// <returns>
/// <para>Type: <c>LPWSTR*</c></para>
/// <para>Receives the default phrase as a Unicode string. The calling application must free the string by calling CoTaskMemFree.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquery/nf-structuredquery-irelationship-defaultphrase HRESULT
// DefaultPhrase( LPWSTR *ppszPhrase );
[return: MarshalAs(UnmanagedType.LPWStr)]
string DefaultPhrase();
}
/// <summary>Provides a method for localizing keywords in a specified string.</summary>
// https://docs.microsoft.com/en-us/previous-versions//aa965593(v=vs.85)
[ComImport, Guid("CA3FDCA2-BFBE-4eed-90D7-0CAEF0A1BDA1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
@ -1336,6 +1409,94 @@ namespace Vanara.PInvoke
void GetToken(uint i, out uint pBegin, out uint pLength, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppsz);
}
/// <summary>
/// Creates a new instance of a IQueryParser interface implementation. This instance of the query parser is loaded with the schema
/// for the specified catalog and is localized to a specified language. All other settings are initialized to default settings.
/// </summary>
/// <typeparam name="T">The type of the IQueryParser interface implementation.</typeparam>
/// <param name="qpmgr">The <see cref="IQueryParserManager"/> instance.</param>
/// <param name="pszCatalog">
/// <para>Type: <c>LPCWSTR</c></para>
/// <para>The name of the catalog to use. Permitted values are and an empty string (for a trivial schema with no properties).</para>
/// </param>
/// <param name="langidForKeywords">
/// <para>Type: <c>LANGID</c></para>
/// <para>The LANGID used to select the localized language for keywords.</para>
/// </param>
/// <returns>
/// Receives a pointer to the newly created parser. The calling application must release it by calling its IUnknown::Release method.
/// </returns>
/// <remarks>
/// If %LOCALAPPDATA% is not available, then this method fails. You should call IQueryParserManager::SetOption to point to a
/// different folder like %ProgramData%.
/// </remarks>
public static T CreateLoadedParser<T>(this IQueryParserManager qpmgr, string pszCatalog, uint langidForKeywords) where T : class => (T)qpmgr.CreateLoadedParser(pszCatalog, langidForKeywords, typeof(T).GUID);
/// <summary>Retrieves an enumeration of IEntity objects with one entry for each entity in the loaded schema.</summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="sp">The <see cref="ISchemaProvider"/> instance.</param>
/// <returns>
/// Receives a pointer to an enumeration of entities. The calling application must release it by calling its IUnknown::Release method.
/// </returns>
public static T Entities<T>(this ISchemaProvider sp) => (T)sp.Entities(typeof(T).GUID);
/// <summary>
/// Identifies parts of the input string that the parser did not recognize or did not use when constructing the IQuerySolution
/// condition tree.
/// </summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="qs">The <see cref="IQuerySolution"/> instance.</param>
/// <returns>
/// <para>Type: <c>void**</c></para>
/// <para>Receives a pointer to an enumeration of zero or more IRichChunk objects, each describing one parsing error.</para>
/// </returns>
/// <remarks>
/// <para>
/// Each parsing error is represented by an IRichChunk object in which the position information reflects token counts. The
/// <c>IRichChunk</c> object <c>ppsz</c> string is <c>NULL</c>, and the pValue is a PROPVARIANT that contains a <c>lVal</c>
/// identifying the STRUCTURED_QUERY_PARSE_ERROR enumeration.
/// </para>
/// <para>The valid values for <paramref name="riid"/> are __uuidof(IEnumUnknown) and __uuidof(IEnumVARIANT).</para>
/// </remarks>
public static T GetErrors<T>(this IQuerySolution qs) where T : class => (T)qs.GetErrors(typeof(T).GUID);
/// <summary>Retrieves an enumeration of IMetaData objects for this entity.</summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="e">The <see cref="IEntity"/> instance.</param>
/// <returns>Receives the address of a pointer to an enumeration of IMetaData objects.</returns>
public static T MetaData<T>(this IEntity e) where T : class => (T)e.MetaData(typeof(T).GUID);
/// <summary>Retrieves an enumeration of IMetaData objects for this relationship.</summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="r">The <see cref="IRelationship"/> instance.</param>
/// <returns>
/// Receives a pointer to the enumeration of IMetaData objects. There may be multiple pairs with the same key (or the same value).
/// </returns>
public static T MetaData<T>(this IRelationship r) where T : class => (T)r.MetaData(typeof(T).GUID);
/// <summary>Retrieves an enumeration of global IMetaData objects for the loaded schema.</summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="sp">The <see cref="ISchemaProvider"/> instance.</param>
/// <returns>
/// Receives a pointer to an enumeration of the IMetaData objects. The calling application must release it by calling its
/// IUnknown::Release method.
/// </returns>
public static T MetaData<T>(this ISchemaProvider sp) => (T)sp.MetaData(typeof(T).GUID);
/// <summary>Retrieves an enumeration of INamedEntity objects, one for each known named entity of this type.</summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="e">The <see cref="IEntity"/> instance.</param>
/// <returns>
/// Receives the address of a pointer to an enumeration of INamedEntity objects, one for each known named entity of this type.
/// </returns>
public static T NamedEntities<T>(this IEntity e) where T : class => (T)e.NamedEntities(typeof(T).GUID);
/// <summary>Retrieves an enumeration of IRelationship objects, one for each relationship this entity has.</summary>
/// <typeparam name="T">The desired type of the result, either IID_IEnumUnknown or IID_IEnumVARIANT.</typeparam>
/// <param name="e">The <see cref="IEntity"/> instance.</param>
/// <returns>Receives the address of a pointer to the enumeration of the IRelationship objects.</returns>
public static T Relationships<T>(this IEntity e) where T : class => (T)e.Relationships(typeof(T).GUID);
/// <summary>Class interface for ICondition</summary>
[ComImport, Guid("116F8D13-101E-4fa5-84D4-FF8279381935"), ClassInterface(ClassInterfaceType.None)]
public class CompoundCondition { }

View File

@ -359,7 +359,8 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquerycondition/nf-structuredquerycondition-icondition-getsubconditions
// HRESULT GetSubConditions( REFIID riid, void **ppv );
void GetSubConditions(in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetSubConditions(in Guid riid);
/// <summary>Retrieves the property name, operation, and value from a leaf search condition node.</summary>
/// <param name="ppszPropertyName">
@ -380,19 +381,20 @@ namespace Vanara.PInvoke
void GetComparisonInfo([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszPropertyName, out CONDITION_OPERATION pcop, [In, Out] PROPVARIANT ppropvar);
/// <summary>Retrieves the semantic type of the value of the search condition node.</summary>
/// <param name="ppszValueTypeName">
/// <returns>
/// <para>Type: <c>LPWSTR*</c></para>
/// <para>Receives either a pointer to the semantic type of the value as a Unicode string or <c>NULL</c>.</para>
/// </param>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquerycondition/nf-structuredquerycondition-icondition-getvaluetype
// HRESULT GetValueType( LPWSTR *ppszValueTypeName );
void GetValueType([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszValueTypeName);
[return: MarshalAs(UnmanagedType.LPWStr)]
string GetValueType();
/// <summary>Retrieves the character-normalized value of the search condition node.</summary>
/// <param name="ppszNormalization">
/// <returns>
/// <para>Type: <c>LPWSTR*</c></para>
/// <para>Receives a pointer to a Unicode string representation of the value.</para>
/// </param>
/// </returns>
/// <remarks>
/// In <c>Windows 7 and later</c>, if the value of the leaf node is <c>VT_EMPTY</c>, ppwszNormalization points to an empty
/// string. If the value is a string, such as VT_LPWSTR, VT_BSTR or VT_LPSTR, then ppwszNormalization is set to a
@ -401,7 +403,8 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquerycondition/nf-structuredquerycondition-icondition-getvaluenormalization
// HRESULT GetValueNormalization( LPWSTR *ppszNormalization );
void GetValueNormalization([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszNormalization);
[return: MarshalAs(UnmanagedType.LPWStr)]
string GetValueNormalization();
/// <summary>
/// For a leaf node, <c>ICondition::GetInputTerms</c> retrieves information about what parts (or ranges) of the input string
@ -495,5 +498,24 @@ namespace Vanara.PInvoke
// HRESULT GetData( ULONG *pFirstPos, ULONG *pLength, LPWSTR *ppsz, PROPVARIANT *pValue );
void GetData(out uint pFirstPos, out uint pLength, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppsz, [In, Out] PROPVARIANT pValue);
}
/// <summary>
/// Retrieves a collection of the subconditions of the search condition node and the IID of the interface for enumerating the collection.
/// </summary>
/// <typeparam name="T">
/// The desired type of the enumerating interface: either IID_IEnumUnknown, IID_IEnumVARIANT or (for a negation condition) IID_ICondition.
/// </typeparam>
/// <param name="c">The <see cref="ICondition"/> instance.</param>
/// <returns>
/// Receives a collection of zero or more ICondition objects. Each object is a subcondition of this condition node. If
/// <typeparamref name="T"/> was IID_ICondition and this is a negation condition, this parameter receives the single subcondition.
/// </returns>
/// <remarks>
/// <para>If the subcondition is a negation node, the return value is set to an enumeration of one element.</para>
/// <para>If the node is a conjunction or disjunction node, the return value is set to an enumeration of the subconditions.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/structuredquerycondition/nf-structuredquerycondition-icondition-getsubconditions
// HRESULT GetSubConditions( REFIID riid, void **ppv );
public static T GetSubConditions<T>(this ICondition c) where T : class => (T)c.GetSubConditions(typeof(T).GUID);
}
}

View File

@ -786,7 +786,7 @@ namespace Vanara.Windows.Shell
var l = new List<PROPERTYKEY>(Count);
for (uint i = 0; i < Count; i++)
{
using (var p = new ComReleaser<IPropertyChange>(changes.GetAt(i, typeof(IPropertyChange).GUID)))
using (var p = new ComReleaser((IPropertyChange)changes.GetAt(i, typeof(IPropertyChange).GUID)))
l.Add(p.Item.GetPropertyKey());
}
return l;

View File

@ -92,7 +92,7 @@ namespace Vanara.Windows.Shell
/// <value>The default save folder.</value>
public ShellItem DefaultSaveFolder
{
get => Open(lib.GetDefaultSaveFolder(DEFAULTSAVEFOLDERTYPE.DSFT_DETECT, typeof(IShellItem).GUID));
get => Open(lib.GetDefaultSaveFolder<IShellItem>(DEFAULTSAVEFOLDERTYPE.DSFT_DETECT));
set => lib.SetDefaultSaveFolder(DEFAULTSAVEFOLDERTYPE.DSFT_DETECT, value.iShellItem);
}
@ -154,13 +154,13 @@ namespace Vanara.Windows.Shell
/// <param name="filter">A value that determines the folders to get.</param>
/// <returns>A <see cref="ShellItemArray"/> containing the child folders.</returns>
public ShellLibraryFolders GetFilteredFolders(LibraryFolderFilter filter = LibraryFolderFilter.AllItems) =>
new ShellLibraryFolders(lib, lib.GetFolders((LIBRARYFOLDERFILTER)filter, typeof(IShellItemArray).GUID));
new ShellLibraryFolders(lib, lib.GetFolders<IShellItemArray>((LIBRARYFOLDERFILTER)filter));
/// <summary>Resolves the target location of a library folder, even if the folder has been moved or renamed.</summary>
/// <param name="item">A ShellItem object that represents the library folder to locate.</param>
/// <param name="timeout">The maximum time the method will attempt to locate the folder before returning. If the folder could not be located before the specified time elapses, an error is returned.</param>
/// <returns>The resulting target location.</returns>
public ShellItem ResolveFolder(ShellItem item, TimeSpan timeout) => Open(lib.ResolveFolder(item.iShellItem, Convert.ToUInt32(timeout.TotalMilliseconds), typeof(IShellItem).GUID));
public ShellItem ResolveFolder(ShellItem item, TimeSpan timeout) => Open(lib.ResolveFolder<IShellItem>(item.iShellItem, Convert.ToUInt32(timeout.TotalMilliseconds)));
/// <summary>Shows the library management dialog box, which enables users to manage the library folders and default save location.</summary>
/// <param name="parentWindow">The handle for the window that owns the library management dialog box. The value of this parameter can be NULL.</param>