using System; using Vanara.PInvoke; using static Vanara.PInvoke.Ole32; using static Vanara.PInvoke.OleAut32; using static Vanara.PInvoke.Shell32; namespace Vanara.Windows.Shell { /// /// Wraps the functionality of IInitializeCommand. When deriving, handling the event is optional. /// /// /// public abstract class ShellCommand : ComObject, IInitializeCommand { /// Initializes a new instance of the class. protected ShellCommand() : base() { } /// Initializes a new instance of the class. /// The context within which the COM object is to be run. /// Indicates how connections are made to the class object. protected ShellCommand(CLSCTX classContext, REGCLS classUse) : base(classContext, classUse) { } /// Occurs when the shell command is initialized. public event EventHandler InitializeCommand; /// Gets the name of the command returned by IInitializeCommand.Initialize. /// /// The name of the command as found in the registry. This value is until IInitializeCommand.Initialize /// is called by the host. /// public string CommandName { get; private set; } /// Gets the properties exposed through IInitializeCommand.Initialize. /// /// Gets a instance. This value is until IInitializeCommand.Initialize is /// called by the host. /// public PropertyBag Properties { get; private set; } /// HRESULT IInitializeCommand.Initialize(string pszCommandName, IPropertyBag ppb) { CommandName = pszCommandName; Properties = new PropertyBag(ppb); InitializeCommand?.Invoke(this, EventArgs.Empty); return HRESULT.S_OK; } } }