Explorer context menu problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gilad

    #1

    Explorer context menu problem

    Hi, I seem to be having a problem getting a context menu to work in
    Explorer. The menu item installs fine, but when I click it a message box
    should pop up indicating the command was received and handled.
    Unfortunately, nothing occurs.

    I suspect that I am doing something wrong with the command ID for the
    menu item, but I can't figure out what. After registering my DLL, the
    menu item "my context menu" appears if I right-click any file. If I
    highlight the menu item with my mouse, the information on Explorer's
    status bar reads "Encrypt the selected files". My "GetCommandStri ng()"
    implementation is as follows (nothing about encryption, as you can see):


    void IContextMenu.Ge tCommandString( int idCmd, uint uFlags, int
    pwReserved, StringBuilder commandString, int cchMax)
    {
    switch(uFlags)
    {
    case (uint)GCS.VERB:
    commandString = new StringBuilder(" ...");
    break;
    case (uint)GCS.HELPT EXT:
    commandString = new StringBuilder(" ...");
    break;
    }
    }


    This is obviously suspect. Then, if I click on the item, no message box
    appears. I've included the relevant parts of my code below.

    This is where I setup the menu, and return an incremented command ID:


    int IContextMenu.Qu eryContextMenu( uint hMenu, uint iMenu, int
    idCmdFirst, int idCmdLast, uint uFlags)
    {

    int id = 0;
    if ( (uFlags & 0xf) == 0 || (uFlags & (uint)CMF.CMF_E XPLORE) != 0)
    {
    uint nselected = Helpers.DragQue ryFile(m_hDrop, 0xffffffff, null, 0);
    if (nselected == 1)
    {
    StringBuilder sb = new StringBuilder(1 024);
    Helpers.DragQue ryFile(m_hDrop, 0, sb, sb.Capacity + 1);
    m_fileName = sb.ToString();

    }


    MENUITEMINFO mii = new MENUITEMINFO();
    mii.cbSize = 48;
    mii.fMask = (uint)MIIM.ID | (uint)MIIM.TYPE | (uint)MIIM.STAT E;
    mii.wID = idCmdFirst+id;
    mii.fType = (uint)MF.STRING ;
    mii.dwTypeData = "my context menu";
    mii.fState = (uint)MF.ENABLE D;
    Helpers.InsertM enuItem(hMenu, (uint)iMenu++, 1, ref mii);


    }

    return idCmdFirst+id+1 ;

    }


    Here is my "InvokeCommand( )" implementation, which should show a simple
    message box.


    void IContextMenu.In vokeCommand (IntPtr pici)
    {

    try
    {

    Type typINVOKECOMMAN DINFO = Type.GetType("T agSet.INVOKECOM MANDINFO");
    INVOKECOMMANDIN FO ici =
    (INVOKECOMMANDI NFO)Marshal.Ptr ToStructure(pic i, typINVOKECOMMAN DINFO);

    MessageBox.Show ("InvokeCommand ");

    }
    catch(Exception )
    {
    }
    }


    Any help would be appreciated. Thanks, JA
  • Mattias Sjögren

    #2
    Re: Explorer context menu problem


    First of all, you may want to think twice before writing a shell
    extension in C# at all. There are good reasons why you shouldn't. See
    http://blogs.msdn.com/junfeng/archiv...18/494572.aspx


    It's hard to say exactly what's wrong without seeing your interface
    and function declarations. But here are some general comments.


    [color=blue]
    >void IContextMenu.Ge tCommandString( int idCmd, uint uFlags, int
    >pwReserved, StringBuilder commandString, int cchMax)
    >{
    > switch(uFlags)
    > {
    > case (uint)GCS.VERB:
    > commandString = new StringBuilder(" ...");
    > break;
    > case (uint)GCS.HELPT EXT:
    > commandString = new StringBuilder(" ...");
    > break;
    > }
    >}[/color]

    The value you assign to commandString here will not be seen by the
    caller since it's passed by value.

    [color=blue]
    > Type typINVOKECOMMAN DINFO = Type.GetType("T agSet.INVOKECOM MANDINFO");[/color]

    You may want to consider using the typeof operator instead of
    Type.GetType here.


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • gilad

      #3
      Re: Explorer context menu problem

      Mattias Sjögren wrote:[color=blue]
      > First of all, you may want to think twice before writing a shell
      > extension in C# at all. There are good reasons why you shouldn't. See
      > http://blogs.msdn.com/junfeng/archiv...18/494572.aspx[/color]

      Thanks, Mattias, for the note. I'll probably switch gears now.

      Also, I got it to work after restarting my computer. Explorer had to be
      restarted, I think, to release module completely.

      JA

      Comment

      Working...