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

Method GetCommandString

PathCopyCopy/src/PathCopyCopyContextMenuExt.cpp:601–690  ·  view source on GitHub ↗

IContextMenu::GetCommandString Invoked by the shell to get a text description for our menu item. @param p_CmdId Offset of ID of command for which to query text, relative to our first command ID. @param p_Flags Type of information or action requested; see MSDN for details. @param p_pReserved Reserved; unused. @param p_pBuffer Pointer to memory buffer where to copy a null-terminated string. Note:

Source from the content-addressed store, hash-verified

599// @return S_OK if successful, otherwise an error code.
600//
601[[gsl::suppress(c.128)]]
602STDMETHODIMP CPathCopyCopyContextMenuExt::GetCommandString(
603 UINT_PTR p_CmdId,
604 UINT p_Flags,
605 UINT* p_pReserved,
606 LPSTR p_pBuffer,
607 UINT p_BufferSize)
608{
609 HRESULT hRes = S_OK;
610
611 try {
612 // Check what is requested.
613 if ((p_Flags == GCS_VERBA) || (p_Flags == GCS_VERBW)) {
614 // We do not support verb invokation.
615 hRes = E_NOTIMPL;
616 } else if ((p_Flags == GCS_VALIDATEA) || (p_Flags == GCS_VALIDATEW)) {
617 // We need to validate command ID.
618 hRes = S_FALSE;
619 if (m_FirstCmdId.has_value()) {
620 if ((m_mPluginsByCmdId.find(*m_FirstCmdId + p_CmdId) != m_mPluginsByCmdId.end()) ||
621 (m_SettingsCmdId.has_value() && (*m_FirstCmdId + p_CmdId) == *m_SettingsCmdId)) {
622
623 // Either it's a plugin or a special menu item.
624 hRes = S_OK;
625 }
626 }
627 } else if (p_Flags == GCS_HELPTEXTA) {
628 // Call this method to get the Unicode version.
629 std::wstring buffer(p_BufferSize, L'\0');
630 hRes = this->GetCommandString(p_CmdId,
631 GCS_HELPTEXTW,
632 p_pReserved,
633 reinterpret_cast<LPSTR>(&*buffer.begin()),
634 p_BufferSize);
635 if (SUCCEEDED(hRes)) {
636 // Convert it to a single-byte string and return it.
637 ATL::CStringA aBuffer(buffer.c_str());
638 if (::strcpy_s(p_pBuffer, p_BufferSize, aBuffer) == 0) {
639 hRes = S_OK;
640 } else {
641 hRes = E_FAIL;
642 }
643 }
644 } else if (p_Flags == GCS_HELPTEXTW) {
645 // A Unicode help string is requested.
646 if (p_pBuffer != nullptr) {
647 // Try finding the plugin that handles this command ID.
648 CmdIdPluginM::const_iterator it = m_mPluginsByCmdId.end();
649 if (m_FirstCmdId.has_value()) {
650 it = m_mPluginsByCmdId.find(*m_FirstCmdId + p_CmdId);
651 }
652 if (it != m_mPluginsByCmdId.end()) {
653 // Found the plugin, ask for its help text.
654 std::wstring helpText = it->second->HelpText();
655
656 // Return help text.
657 if (::wcscpy_s(reinterpret_cast<LPWSTR>(p_pBuffer), p_BufferSize, helpText.c_str()) != 0) {
658 hRes = E_FAIL;

Callers

nothing calls this directly

Calls 3

endMethod · 0.45
beginMethod · 0.45
HelpTextMethod · 0.45

Tested by

no test coverage detected