How to Implement IContextMenu and IObjectWithSite

Windows Mobile 6.5

The following C++ code snippet demonstrates the structure of the shortcut menu extension component class definition.

The following code example demonstrates how to implement IContextMenu and IObjectWithSite.

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
class CMyComp : public IContextMenu, IObjectWithSite
        CMyComp();   // Constructor.
        ~CMyComp();  // Destructor.

        // IUnknown methods.
        STDMETHOD (QueryInterface) (REFIID riid, LPVOID *ppv);
        STDMETHOD_(ULONG, AddRef)  (void);
        STDMETHOD_(ULONG Release)  (void);

        // IContextMenu methods.
        STDMETHOD (GetCommandString) (UINT idCmd, UINT uFlags,
                   UINT *pwReserved,LPSTR pszName, UINT cchMx);
        STDMETHOD (InvokeCommand)    (LPCMINVOKECOMMANDINFO pici);
        STDMETHOD (QueryContextMenu) (hmenu, UINT indexMenu,
                   UINT idCmdFirs, UINT idCmdLast, UINT uFlags);

        // IObjectWithSite methods.
        STDMETHOD (GetSite) (REFIID riid, void **ppvSite);
        STDMETHOD (SetSite) (IUnknown *pUnkSite);

        // CMyComp methods.
        // None.

        ULONG    m_cRef;       // Reference count.
        IUnknown m_punkSite;   // Site (owner) pointer.

Community Additions