MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / InvokeCommand

Method InvokeCommand

PathCopyCopy/src/PathCopyCopyContextMenuExt.cpp:537–584  ·  view source on GitHub ↗

IContextMenu::InvokeCommand Invoked by the shell when the user selects one of our menu items. We do our stuff here. @param p_pCommandInfo Pointer to struct containing command information. @return S_OK if successful, otherwise an error code.

Source from the content-addressed store, hash-verified

535// @return S_OK if successful, otherwise an error code.
536//
537[[gsl::suppress(c.128)]]
538STDMETHODIMP CPathCopyCopyContextMenuExt::InvokeCommand(
539 CMINVOKECOMMANDINFO* p_pCommandInfo)
540{
541 HRESULT hRes = S_OK;
542
543 try {
544 if ((p_pCommandInfo == nullptr) || (p_pCommandInfo->cbSize < sizeof(CMINVOKECOMMANDINFO))) {
545 hRes = E_INVALIDARG;
546 } else {
547 // Get offset of invoked command.
548#pragma warning(suppress: 26490) // No choice but to use reinterpret_cast because of Win32 API
549 const UINT_PTR cmdOffset = reinterpret_cast<UINT_PTR>(p_pCommandInfo->lpVerb);
550 if ((cmdOffset & 0xFFFF0000) != 0) {
551 // We do not support verb invokation.
552 hRes = E_FAIL;
553 } else if (!m_FirstCmdId.has_value()) {
554 // We do not have menu items, so we can't invoke anything.
555 hRes = E_INVALIDARG;
556 } else {
557 // Check which command it is that is invoked.
558 const UINT_PTR cmdId = cmdOffset + *m_FirstCmdId;
559 const auto itId = m_mPluginsByCmdId.find(cmdId);
560 if (itId == m_mPluginsByCmdId.end()) {
561 // This is not a recognized plugin command ID.
562 if (m_SettingsCmdId.has_value() && *m_SettingsCmdId == cmdId) {
563 PCC::SettingsApp().Launch();
564 hRes = S_OK;
565 } else if (m_SubMenuCmdId.has_value() && *m_SubMenuCmdId == cmdId) {
566 hRes = E_INVALIDARG;
567 } else {
568 hRes = E_FAIL;
569 }
570 } else {
571 // Fetch plugin reference for this command ID.
572 PCC::PluginSP spPlugin = itId->second;
573
574 // Act on the files using the plugin.
575 hRes = ActOnFiles(spPlugin, p_pCommandInfo->hwnd);
576 }
577 }
578 }
579 } catch (...) {
580 hRes = E_UNEXPECTED;
581 }
582
583 return hRes;
584}
585
586//
587// IContextMenu::GetCommandString

Callers

nothing calls this directly

Calls 3

SettingsAppClass · 0.85
LaunchMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected