c++windowsvisual-studio-2010contextmenuwindows-shell

Registering Windows context menu handler provided by Microsoft's All-In-One framework (CppShellExtContextMenuHandler project)


I've been using the CppShellExtContextMenuHandler sample project from Microsoft's All-In-One framework to add a custom menu item + icon to windows's context menu.

However, it seems that I can't register the DLL provided by this sample on other computers than mine. The DLL, compiled on a Windows 7 x86 machine from unmodified code, doesn't run on:

I get:

LoadLibrary(CppShellExtContextMenuHandler.dll) Failed to find specified procedure

(translated) on the XP machine

The module "CppShellExtContextMenuHandler.dll" failed to load.

Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent .DLL files.

The specified module could not be found

on the other Windows 7 machine

I use Regsvr32 CppShellExtContextMenuHandler.dll in the commandline to register the DLL.

Did anyone encounter this problem? Did I miss something (dependencies/project config)? I'm not sure how to debug this one.

Thank you for your help!

PS1: Code is available here: http://1code.codeplex.com/releases/view/71395, under ./Visual Studio 2010/CppShellExtContextMenuHandler in the package.

PS2: Compiled version of the sample is here: https://fgt.bo/GmQ


Solution

  • Finally found the answer, thanks to Choosing a Deployment Method on MSDN.

    To make the DLL file compiled from the CppShellExtContextMenuHandler sample work on non-dev computers, you need to accompany it with the VC++ Runtime DLLs it depends on.

    I used the wonderful tool (DependencyWalker) on a client's (non-dev) machine to get the name of the DLLs my context menu handler depended on (the tool indicates which of them are missing on the target computer!).

    It turned out I had to redistribute the msvcr100.dll and msvcp100.dll files from [Program Files\Microsoft Visual Studio 10.0\VC\Redist] along with the CppShellExtContextMenuHandler.dll file to make it work.

    To make the handler work on Windows XP, I also had to replace the two occurences of

    hr = HRESULT_FROM_WIN32(RegDeleteTree(...

    by:

    hr = SHDeleteKey(...

    ...in the Reg.cpp file. In fact, according to C++ Windows Shell context menu handler Sample, the RegDeleteTree function isn't available on XP. The SHDeleteKey is equivalent and can be found in Shlwapi.h, on all versions of windows I tested.

    Thank you for your time reading and trying to solve this!