/// <include file='doc\OleMenuCommandService.uex' path='docs/doc[@for="OleMenuCommandService.IOleCommandTarget.Exec"]/*' /> /// <internalonly/> /// <devdoc> /// Executes the given command. /// </devdoc> int IOleCommandTarget.Exec(ref Guid guidGroup, uint nCmdId, uint nCmdExcept, IntPtr pIn, IntPtr vOut) { int hr = NativeMethods.S_OK; MenuCommand cmd = FindCommand(guidGroup, (int)nCmdId, ref hr); // If the command is not supported check if it can be handled by the parent command service if ((cmd == null || !cmd.Supported) && _parentTarget != null) { return(_parentTarget.Exec(ref guidGroup, nCmdId, nCmdExcept, pIn, vOut)); } else if (cmd != null) { object o = null; if (pIn != (IntPtr)0) { o = Marshal.GetObjectForNativeVariant(pIn); } OleMenuCommand vsCmd = cmd as OleMenuCommand; if (null == vsCmd) { cmd.Invoke(o); } else { vsCmd.Invoke(o, vOut); } } return(hr); }
/// <include file='doc\OleMenuCommandService.uex' path='docs/doc[@for="OleMenuCommandService.IOleCommandTarget.Exec"]/*' /> /// <internalonly/> /// <devdoc> /// Executes the given command. /// </devdoc> int IOleCommandTarget.Exec(ref Guid guidGroup, uint nCmdId, uint nCmdExcept, IntPtr pIn, IntPtr vOut) { const uint vsCmdOptQueryParameterList = 1; int hr = NativeMethods.S_OK; MenuCommand cmd = FindCommand(guidGroup, (int)nCmdId, ref hr); // If the command is not supported check if it can be handled by the parent command service if ((cmd == null || !cmd.Supported) && _parentTarget != null) { return(_parentTarget.Exec(ref guidGroup, nCmdId, nCmdExcept, pIn, vOut)); } else if (cmd != null) { // Try to see if the command is a OleMenuCommand. OleMenuCommand vsCmd = cmd as OleMenuCommand; // Check the execution flags; uint loWord = LoWord(nCmdExcept); // If the command is not an OleMenuCommand, it can handle only the default // execution. if (((uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT != loWord) && (null == vsCmd)) { return(NativeMethods.S_OK); } object o = null; if (pIn != IntPtr.Zero) { o = Marshal.GetObjectForNativeVariant(pIn); } if (null == vsCmd) { cmd.Invoke(o); } else { switch (loWord) { // Default execution of the command: call the Invoke method case (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT: vsCmd.Invoke(o, vOut); break; case (uint)OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP: // Check the hi word of the flags to see what kind of help // is needed. We handle only the request for the parameters list. if (vsCmdOptQueryParameterList == HiWord(nCmdExcept) && IntPtr.Zero != vOut) { // In this case vOut is a pointer to a VARIANT that will receive // the parameters description. if (!string.IsNullOrEmpty(vsCmd.ParametersDescription)) { Marshal.GetNativeVariantForObject(vsCmd.ParametersDescription, vOut); } } break; default: break; } } } return(hr); }