views:

1161

answers:

2

I was wanting to write a simple windows shell extension to add to the context menu, and C# is the language I most use these days. Is it a decent choice for a shell extension? Are the interfaces easy to get to with it? Is there additional overhead that causes the menu to be slower to pop up?

Any one have good pointers for getting started?

+6  A: 

A Raymond's post: Do not write in-process shell extensions in managed code.

GSerg
it can be done but its a bad idea. I know MS dev team that wrote shell ext in c# and they ended up recoding in c++ native
pm100
The latest .Net 4.0 runtime supports in process side-by-side loading of the .Net 4.0 runtime (and ALL future runtimes) with earlier .Net runtimes.See following excerpt from http://msdn.microsoft.com/en-us/magazine/ee819091.aspx "With the ability to have multiple runtimes in process with any other runtime, we can now offer general support for writing managed shell extensions—even those that run in-process with arbitrary applications on the machine."
logicnp
Are the authors implying that it's OK to drop support for apps written in FWs previous to 4.0?
GSerg
+2  A: 

At the risk of looking like a shill, EZShellExtensions is a wonderful (but non-free) framework for shell extension development in C#. You can write a simple context menu extension with about 20 lines of code and, best of all, never have to mess with COM interfaces. My company uses it (and their namespace extension framework) for a set of extensions currently in use by tens of thousands of customers and, for what it's worth, we've never had a problem with the CLR conflict described above.

Here's a quick sample to show how easy it is:

[Guid("00000000-0000-0000-0000-000000000000"), ComVisible(true)]
[TargetExtension(".txt", true)]
public class SampleExtension : ContextMenuExtension
{
   protected override void OnGetMenuItems(GetMenuitemsEventArgs e)
   {
      e.Menu.AddItem("Sample Extension", "sampleverb", "Status/help text");
   }

   protected override bool OnExecuteMenuItem(ExecuteItemEventArgs e)
   {
      if (e.MenuItem.Verb == "sampleverb")
         ; // logic
      return true;
   }

   [ComRegisterFunction]
   public static void Register(Type t)
   {
      ContextMenuExtension.RegisterExtension(typeof(SampleExtension));
   }

   [ComUnregisterFunction]
   public static void UnRegister(Type t)
   {
      ContextMenuExtension.UnRegisterExtension(typeof(SampleExtension));
   }
}
ladenedge