Search code examples
c++shellvisual-c++dllcom

How would dll shell extension know the program location to execute?


I have now a context menu shell extension(dll) in C++ and would like to bundle this with a renaming program of mine.

My question is, once the dll is loaded and Execute is called via context menu, how would the shell extension know the location of the program to launch?

I will have inno setup to include my shell extension(dll). My understanding is the shell extension will handle passing the selected files path to a renaming program installed on the system. But how can the shell know to call the program? regards


Solution

  • The Shell has no concept of a "renaming program", that is a private detail of your Shell extension's implementation. If your Shell extension is trying to launch an external program, it is your responsibility to make sure your Shell extension knows where to find that program.

    For instance, by having your Inno setup prompt the user, or even by you providing a separate configuration UI along with your Shell extension, and then save the user's choice in the Registry, or in a file in the user's profile, anywhere that your Shell extension can find it later on when needed.

    Or, if the program in question already stores its own installation path somewhere, like in the Registry, just have your Shell extension retrieve that location directly when needed.

    Either way, your Shell extension would have to remember the input file path(s) that are passed to its IShellExtInit::Initialize() implementation, and then your IContextMenu::InvokeCommand() implementation would pass those path(s) to the external program after determining where it is located.