using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Shell32
{
///
/// Enables a client of Shell item activation (including callers of ShellExecuteEx and IContextMenu::InvokeCommand) to be given a
/// chance to veto or perform some action before the activation of verb handlers.
///
///
/// This interface is implemented by an object reachable through the site chain provided to ShellExecuteEx or the context menu
/// handler. Applications will return this object in their IServiceProvider::QueryService implementation when asked for the
/// service ID SID_SHandlerActivationHost.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ihandleractivationhost
[ComImport, Guid("35094a87-8bb1-4237-96c6-c417eebdb078"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IHandlerActivationHost
{
///
/// Notifies a client of ShellExecuteEx that a handler is about to be created, giving that client the opportunity to display UI
/// confirming the use of that handler or reject it by returning a specific error code.
///
/// Identifies the handler.
///
/// The Shell item objects that will be passed to the handler. Typically there is only one, but in some cases there can be more
/// than one.
///
///
/// Provides access to information about the handler that will be invoked. This object also supports IHandlerInfo2 on
/// versions of Windows that support that interface.
///
///
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code,
/// HRESULT_FROM_WIN32(ERROR_CANCELLED) inciates that the ShellExecute call should be canceled,
/// EXECUTE_E_LAUNCH_APPLICATION indicates that this handler should not be used, but if there is another it should be used.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ihandleractivationhost-beforecocreateinstance
// HRESULT BeforeCoCreateInstance( REFCLSID clsidHandler, IShellItemArray *itemsBeingActivated, IHandlerInfo *handlerInfo );
[PreserveSig]
HRESULT BeforeCoCreateInstance(in Guid clsidHandler, IShellItemArray itemsBeingActivated, IHandlerInfo handlerInfo);
///
/// Notifies a client of ShellExecuteEx that a process is about to created, giving that client the opportunity to display UI
/// confirming that or reject it by returning a specific error code.
///
/// The fully qualified path to the process executable, or in some cases a DLL path.
///
/// The full command line that will be passed to CreateProcess including the arguments that the handler requested via its registration.
///
///
/// Provides access to information about the handler that will be invoked. This object also supports IHandlerInfo2 on
/// versions of windows that support that interface. This object also implements IObjectWithSelection. This can be used to get
/// the Shell item, or items in some cases, that are being launched.
///
///
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code,
/// HRESULT_FROM_WIN32(ERROR_CANCELLED) inciates that the ShellExecute call should be canceled.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ihandleractivationhost-beforecreateprocess
// HRESULT BeforeCreateProcess( LPCWSTR applicationPath, LPCWSTR commandLine, IHandlerInfo *handlerInfo );
[PreserveSig]
HRESULT BeforeCreateProcess([MarshalAs(UnmanagedType.LPWStr)] string applicationPath, [MarshalAs(UnmanagedType.LPWStr)] string commandLine, IHandlerInfo handlerInfo);
}
/// Supplies methods that provide information about the handler to methods of the IHandlerActivationHost interface.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ihandlerinfo
[PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IHandlerInfo")]
[ComImport, Guid("997706ef-f880-453b-8118-39e1a2d2655a"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IHandlerInfo
{
/// Retrieves the display name of the application that implemented the handler.
///
/// Type: LPWSTR*
///
/// A pointer to a string that, when this method returns successfully, receives the display name. If no display name could be
/// found, the name of the application's .exe file is used.
///
///
///
/// Type: HRESULT
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ihandlerinfo-getapplicationdisplayname
// HRESULT GetApplicationDisplayName( LPWSTR *value );
[PreserveSig]
HRESULT GetApplicationDisplayName([MarshalAs(UnmanagedType.LPWStr)] out string value);
/// Retrieves the name of the publisher of the application that implemented the handler.
///
/// Type: LPWSTR*
/// A pointer to a string that, when this method returns successfully, receives the publisher's name.
///
///
/// Type: HRESULT
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ihandlerinfo-getapplicationpublisher
// HRESULT GetApplicationPublisher( LPWSTR *value );
[PreserveSig]
HRESULT GetApplicationPublisher([MarshalAs(UnmanagedType.LPWStr)] out string value);
/// Retrieves the icon of the application that implemented the handler.
///
/// Type: LPWSTR*
/// A pointer to a string that, when this method returns successfully, receives the path of the icon.
///
///
/// Type: HRESULT
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ihandlerinfo-getapplicationiconreference
// HRESULT GetApplicationIconReference( LPWSTR *value );
[PreserveSig]
HRESULT GetApplicationIconReference([MarshalAs(UnmanagedType.LPWStr)] out string value);
}
/// Undocumented.
///
[PInvokeData("shobjidl_core.h")]
[ComImport, Guid("31cca04c-04d3-4ea9-90de-97b15e87a532"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IHandlerInfo2 : IHandlerInfo
{
/// Undocumented.
///
/// Type: LPWSTR*
/// A pointer to a string that, when this method returns successfully, receives the application identifier.
///
///
/// Type: HRESULT
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
[PreserveSig]
HRESULT GetApplicationId([MarshalAs(UnmanagedType.LPWStr)] out string value);
}
}
}