Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Windows shell extension in Visual Studio 2010

I'm trying to create an absurdly simple shell extension in C++ using Visual Studio 2010, but I can't even seem to get the examples out there to work as a starting point.

I'm using Windows 7 x64.

I've tried this Visual Studio template, but once I get the template to work in VS2010, I have a host of errors that I'm not sure how to fix.

I've tried The Complete Idiot's Guide to Writing Shell Extensions, and once the demo compiles all the right registry settings etc. are created but no context menu appears.

I've looked at this C# COM Interop example, but I've been left confused as to whether it is safe to use C# thanks to this article*, but it looks like I might be OK if I use .NET 4 because it supports in process side-by-side CLR hosting.

  • in short: historically two versions of .NET cannot run in the same process, and the way shell extensions work is they inject themselves into a process. So if .NET 3.5 gets injected into a .NET 2 process - bang

So, can I use .NET 4.0 now?

Is there a working, downloadable, VS2010 solution that adds a simple shell extension?

I used to be not so bad with C++ back in the day, but after years of moulding to .NET I'm quite rusty, and as such, fiddling with the details to fix the host of errors I'm getting on the existing examples is proving... fiddly!

I could really do with a clean slate to start with that I can break myself and figure out what I did wrong!

like image 345
joshcomley Avatar asked Sep 08 '10 18:09

joshcomley


People also ask

What is Microsoft Visual Studio 2010 Shell?

The Visual Studio Shell enables Visual Studio Partners to build tools and applications on top of the Visual Studio IDE. Using integrated mode, you can release a Visual Studio extension for use by customers who have not installed Visual Studio.

What is Windows shell extension?

Shell extensions can be represented as individual plug-ins to Windows Explorer. They can be used to add a new tab to the Properties window, change a file preview, and do other things. Before taking any action, the Shell calls registered extension handlers to customize this action.

How do I open Visual Studio Shell?

The Visual Studio terminal is built on top of Windows Terminal. To open the terminal in Visual Studio, select View > Terminal.


1 Answers

I struggled with this for a while and had limited success with the code project article due to x64 issues and SDK differences.

I recently picked the project back up and started over using the MS all-in-one code sample and I am very pleased. It makes a simple example context menu and x64 works out of the box: http://code.msdn.microsoft.com/windowsdesktop/CppShellExtContextMenuHandl-410a709a

To get it running on your machine:

  1. download the code via the all-in-one sample browser or use the direct link.
  2. Open project in VS under admin rights
  3. switch build config to x64 and build it
  4. Kill all explorer sessions
  5. Locate the new dll and run regsvr32.exe .\CppShellExtContextMenuHandler.dll
  6. open explorer again and right click a .cpp file to see the new menu
  7. remove it by running same command with /u flag

My next step is to get debugging working and I think this may do the trick: msdn

like image 71
wtjones Avatar answered Oct 11 '22 20:10

wtjones