NO

Author Topic: Context menu shell extension update?  (Read 7366 times)

reachjeffs

  • Guest
Context menu shell extension update?
« on: February 11, 2012, 05:42:27 AM »
Has anyone taken the time to update John Findlay's excellent context menu shell extension code (http://www.pellesc.de/source_start.php?file=contextmenuext.zip) so that it works in Win Vista/7?  And even better...what about 64 bit versions of Vista/7?  I've spent a little time trying to muddle through it, but  I'm a BCX basic guy, so I'm not having much luck.  Any help would be greatly appreciated.

Thanks,
Jeff


CommonTater

  • Guest
Re: Context menu shell extension update?
« Reply #1 on: February 11, 2012, 03:07:49 PM »
You can reach John Findlay directly from his website at ... http://www.johnfindlay.plus.com/pellesc/index.html
 
Also... if you tell us exactly what you are trying to accomplish, there may be other ways...
 


 
« Last Edit: February 11, 2012, 03:11:07 PM by CommonTater »

reachjeffs

  • Guest
Re: Context menu shell extension update?
« Reply #2 on: February 13, 2012, 07:19:08 PM »
Thanks for the reply Tater.  I did actually try to reach out to John a few months ago, but he didn't have time to upgrade the example. 

All I personally need, is for the extension to add one item to the context menu for, let's say...TXT files.  The basics of this are already handled in John's existing example, so all I really need is to figure out what changes are necessary to get it working in 32 and 64 bit Vista/7.  John's code already works great with Win9x through WinXP. 

That being said, if there are other context menu shell extension code samples out there that work with Pelles, then I'd be happy to give them a shot too.  Just point me in the right direction.

CommonTater

  • Guest
Re: Context menu shell extension update?
« Reply #3 on: February 13, 2012, 07:40:03 PM »
Thanks for the reply Tater.  I did actually try to reach out to John a few months ago, but he didn't have time to upgrade the example. 

All I personally need, is for the extension to add one item to the context menu for, let's say...TXT files.  The basics of this are already handled in John's existing example, so all I really need is to figure out what changes are necessary to get it working in 32 and 64 bit Vista/7.  John's code already works great with Win9x through WinXP. 

That being said, if there are other context menu shell extension code samples out there that work with Pelles, then I'd be happy to give them a shot too.  Just point me in the right direction.

If for example you want to add a new command for text files... say something like "Compress" along with the usual Open or Edit commands that can be done by writing a new verb into the file associations part of the registry. If you look in the User Contributions section you will find a library for Windows File Associations that can do that for you.  See Attachment 1, below... The circled items were added with the library.
 
http://forum.pellesc.de/index.php?topic=3685.0
 
File association verbs are quite easily created or modified...  Attachment 2 shows you the registry structure you need to create...  Take a look in your RegEdit, in HKEY_CLASSES_ROOT ... you should be able to deduce the structure easily enough.
 
Also ... http://msdn.microsoft.com/en-us/library/windows/desktop/cc144104(v=vs.85).aspx
 
 
If it's something more complex, requiring an Active X object or adding new panels to explorer, then things get rather tricky...
« Last Edit: February 13, 2012, 07:53:52 PM by CommonTater »

reachjeffs

  • Guest
Re: Context menu shell extension update?
« Reply #4 on: February 13, 2012, 10:10:43 PM »
I appreciate the info Tater, but I'm afraid I'm more interested in that tricky part.  :)

For the sake of argument, let's say that I want the first 10 characters of the currently selected TXT file displayed in the context menu.  And maybe, the file size and modified date.  Basically...I need dynamic data based on the currently selected file.  I don't want items in the context menu that will shell out to another program.  I want the action to be completed and the results displayed in the context menu as it is drawn.

Maybe I'll put a modified version of John's code together with these ideas in place, and then a shell extension wizard can work some Vista/7 magic on it?

Thanks again,
Jeff

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Context menu shell extension update?
« Reply #5 on: February 13, 2012, 10:29:20 PM »
You can create program that views those things and put that under shell-key.
http://forum.pellesc.de/index.php?topic=3286.msg12388#msg12388
May the source be with you

reachjeffs

  • Guest
Re: Context menu shell extension update?
« Reply #6 on: February 14, 2012, 12:07:14 AM »
You can create program that views those things and put that under shell-key.
http://forum.pellesc.de/index.php?topic=3286.msg12388#msg12388

Thanks timovjl.  I've used that method several times, but in this case I don't want to shell out to an external program.  John's code already has the basic framework for what I need, but it only works thru WinXP.  There are apparently some changes in Vista/7 that prevent it from working.  The extension seems to register properly in 32 bit Vista/7, but it never does display the menu items.

Jeff

CommonTater

  • Guest
Re: Context menu shell extension update?
« Reply #7 on: February 14, 2012, 12:19:05 AM »
I appreciate the info Tater, but I'm afraid I'm more interested in that tricky part.  :)

For the sake of argument, let's say that I want the first 10 characters of the currently selected TXT file displayed in the context menu.  And maybe, the file size and modified date.  Basically...I need dynamic data based on the currently selected file.  I don't want items in the context menu that will shell out to another program.  I want the action to be completed and the results displayed in the context menu as it is drawn.

Maybe I'll put a modified version of John's code together with these ideas in place, and then a shell extension wizard can work some Vista/7 magic on it?

Thanks again,
Jeff

Sounds more like something you'd want to do with a custom tooltip than on a context menu.  Menus are line by line clickable selection devices, not open text display areas.  You might consider doing that on an infotip through the IQueryInfo interface... http://msdn.microsoft.com/en-us/library/windows/desktop/bb761359(v=vs.85).aspx

In either case, yes, that's Active X territory... 
which leaves me to defer to the others, as I've done next to nothing with this.



Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Context menu shell extension update?
« Reply #8 on: February 14, 2012, 01:19:47 PM »
Found something:
WinXP calls CClassFactory_CreateInstance riid=000214E8 IID_IShellExtInit
Win7 calls  CClassFactory_CreateInstance riid=000214E4 IID_IContextMenu

So that problem is in CClassFactory_CreateInstance() in ClassFactory.c.

EDIT:
Is this a proper quick fix ?
Code: [Select]
...
if (pUnkOuter)
return ResultFromScode (CLASS_E_NOAGGREGATION);
// {0x000214e8,0,0,{0xc0,0,0,0,0,0,0,0x46}} {0x000214e4,0,0,{0xc0,0,0,0,0,0,0,0x46}}
if (IsEqualIID (riid, &IID_IShellExtInit) || (IsEqualIID (riid, &IID_IContextMenu) && pCF->m_ulRef == 1))
{
...
« Last Edit: February 14, 2012, 03:16:18 PM by timovjl »
May the source be with you

JohnF

  • Guest
Re: Context menu shell extension update?
« Reply #9 on: February 17, 2012, 05:53:46 PM »
reachjeffs did you see the post from timovjl above?

John

reachjeffs

  • Guest
Re: Context menu shell extension update?
« Reply #10 on: February 17, 2012, 09:54:04 PM »
Oops, I did not see that post.   That change DOES allow the extension to work on Vista 32 bit!  Thank you timovjl!

Any hints on how to compile this for 64 bit?  I tried "Upgrade project to Win64", but I get these errors on compile. 

Code: [Select]
Building ClassFactory.OBJ.
Building ContextMenu.OBJ.
C:\contextmenuext-64\ContextMenu.c(31): warning #2145: Assignment of 'long int __stdcall function(LPCONTEXTMENU, unsigned int, unsigned int, unsigned int *, char *, unsigned int)' to 'long int __stdcall function(LPCONTEXTMENU, unsigned long long int, unsigned int, unsigned int *, char *, unsigned int)'.
Building ContextMenuExt.RES.
Building Main.OBJ.
Building ContextMenuExt.DLL.
POLINK: error: Unresolved external symbol '_DllCanUnloadNow@0'.
POLINK: error: Unresolved external symbol '_DllGetClassObject@12'.
POLINK: error: Unresolved external symbol '_DllRegisterServer@0'.
POLINK: error: Unresolved external symbol '_DllUnregisterServer@0'.
POLINK: fatal error: 4 unresolved external(s).
*** Error code: 1 ***
Done.

Thank you again!

aardvajk

  • Guest
Re: Context menu shell extension update?
« Reply #11 on: February 17, 2012, 10:24:48 PM »
It'll work even better if you replace both ifs with the contents of the first one, ie
Code: [Select]
STDMETHODIMP CClassFactory_CreateInstance(IClassFactory *this, LPUNKNOWN pUnkOuter, REFIID riid,  LPVOID *ppv)
{
    ClassFactoryStruct * pCF = (ClassFactoryStruct*)this;
    *ppv = NULL;
   
    if (pUnkOuter)
        return ResultFromScode (CLASS_E_NOAGGREGATION);

    HRESULT hr = S_OK;
    // Creates the IContextMenu incorperating IShellExtInit interfaces
    IContextMenu * pIContextMenu = CContextMenuExt_Create();

    if (NULL == pIContextMenu)
    {
        return E_OUTOFMEMORY;
    }

    // This puts the IContextMenu interface into 'ppv'
    hr = pIContextMenu->lpVtbl->QueryInterface(pIContextMenu, riid, ppv);
    pIContextMenu->lpVtbl->Release(pIContextMenu);
    return hr;
}

With that it doesn't matter how many references Windows decides to take on the classfactory (timovjl's will fail if a version of Windows decides to AddRef it before calling QueryInterface, for example). It would allow the implementation to check for supported IIDs in one place, but whoever wrote this decided to duplicate the QueryInterface code for IShellExtInit instead of just thunking to the base IContextMenu version like he did for AddRef and Release.

Quote
C:\contextmenuext-64\ContextMenu.c(31): warning #2145: Assignment of 'long int __stdcall function(LPCONTEXTMENU, unsigned int, unsigned int, unsigned int *, char *, unsigned int)' to 'long int __stdcall function(LPCONTEXTMENU, unsigned long long int, unsigned int, unsigned int *, char *, unsigned int)'
This warning is because the second parameter to CContextMenuExt_GetCommandString should be 'UINT_PTR idCmd' not 'UINT idCmd'

The export problem is because there is no stdcall on x64, hence no name decoration. Changing the def file to
Code: [Select]
; ContextMenuExt.Def

LIBRARY "ContextMenuExt"

EXPORTS
DllCanUnloadNow
DllGetClassObject
DllRegisterServer
DllUnregisterServer
should fix it (I don't have 64-bit Pelles C to check)

EDIT:
I've cleaned up some of the code (the handle leaks and bits left in the registry if registration fails, the memory leak of m_pszSource, etc.) It's attached.
« Last Edit: February 18, 2012, 12:18:23 AM by aardvajk »

reachjeffs

  • Guest
Re: Context menu shell extension update?
« Reply #12 on: February 18, 2012, 07:10:40 PM »
Thank you very much aardvajk!  I'll be taking a close look at this tonight.