Microsoft KB Archive/928784

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:34, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


BUG: Nothing happens when you click a menu item on a shortcut menu extension on a Windows Mobile 5.0-based device

Article ID: 928784

Article Last Modified on 5/9/2007



APPLIES TO

  • Windows Mobile 5.0 for Pocket PC
  • Windows Mobile 5.0 for Pocket PC Phone Edition
  • Windows Mobile 5.0 for Smartphones



SYMPTOMS

On a Microsoft Windows Mobile 5.0-based device, nothing happens when you click a menu item on a shortcut menu extension.

Note This problem occurs only for classes that implement the IContextMenu interface and that are called by the SHInvokeContextMenuCommand function.

CAUSE

This problem occurs because the SHInvokeContextMenuCommand function uses the absolute menu item ID in the idCmd parameter that is passed to the IContextMenu::GetCommandString method. The SHInvokeContextMenuCommand function should pass the offset of the idCmd parameter from the idCmdFirst parameter of the IContextMenu::QueryContextMenu method instead.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To work around this problem, modify the IContextMenu::GetCommandString method for shortcut menu extensions that implement the IContextMenu interface and that are called by the SHInvokeContextMenuCommand function.

You can modify the IContextMenu::GetCommandString method so that it determines the correct offset of the idCmd parameter from the idCmdFirst parameter of the IContextMenu::QueryContextMenu method. This makes sure that both the SHInvokeContextMenuCommand function and the applications that directly use IContextMenu interface-based shortcut menu extensions obtain the correct command string for the menu item.

The following code example demonstrates how to modify the IContextMenu::GetCommandString method so that it determines the correct offset.

STDMETHODIMP CMyMenuExtension::GetCommandString(UINT_PTR    idCmd,
                                                UINT        uType,
                                                UINT      * pwReserved,
                                                LPSTR       pszName,
                                                UINT        cchMax)
{
    UINT idCmdInternal = (idCmd >= m_idCmdFirst) ? (idCmd – m_idCmdFirst) : idCmd;

    // Add code here to retrieve the command string that corresponds to the idCmdInternal value.
}

Note You should initialize the m_idCmdFirst data member to zero in the class constructor. Additionally, you should cache the value of the m_idCmdFirst data member whenever the CMyMenuExtension::QueryContextMenu method is called on the object. This makes sure that the modified IContextMenu::GetCommandString method works correctly.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

REFERENCES

For more information about the IContextMenu::GetCommandString method, visit the following Microsoft Developer Network (MSDN) Web site:

For more information about the IContextMenu::QueryContextMenu method, visit the following MSDN Web site:

For more information about the SHInvokeContextMenuCommand function, visit the following MSDN Web site:

Keywords: kbtshoot kbbug KB928784