Home > Ask the Microsoft .Net Development Experts > Visual Studio .NET Questions & Answers > Is developing add-ons for Windows Explorer supported using managed code in .NET?
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

Is developing add-ons for Windows Explorer supported using managed code in .NET?

Chris Sells EXPERT RESPONSE FROM: Chris Sells

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 23 January 2003
I was hoping to find out whether developing add-ons for Windows Explorer is supported using managed code in .NET, and if any samples of this sort of code are available?

>
The Windows File Explorer shell is extensible into a ton of directions, from execution hooks to extend the Run dialog to context menu extensions to augment the built-in context menus for files and folders -- and that's just the tip of the iceberg. These extensions almost all have one thing in common: they depend on COM. Specifically, the Explorer uses custom keys in the registry to find the shell extensions and then depends on COM functions and interfaces to access the custom functionality. Since you can implement COM components in .NET, theoretically you can implement any kind of COM-based Explorer extension you like.

However, practice makes things a lot harder. Almost all of the COM interfaces that need implementing are custom interfaces, which means that they aren't described via a COM type library. Instead, they're described in C/C++ header files, and there are no tools to turn them into the .NET code that's required to call and/or implement them. Instead, you have to write that interop code yourself, by hand. For example, a simple context menu extension requires you to implement three COM interfaces, all of which require code like the following to bring them into the managed world:


[
  ComImport(),
  InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  GuidAttribute("0000010e-0000-0000-C000-000000000046") ]
public interface IDataObject {
  [PreserveSig()]
  int GetData(ref FORMATETC a, ref STGMEDIUM b);
  [PreserveSig()]
  void GetDataHere(int a, ref STGMEDIUM b);
  [PreserveSig()]
  int QueryGetData(int a);
  [PreserveSig()]
  int GetCanonicalFormatEtc(int a, ref int b);
  [PreserveSig()]
  int SetData(int a, int b, int c);
  [PreserveSig()]
  int EnumFormatEtc(uint a, ref Object b);
  [PreserveSig()]
  int DAdvise(int a, uint b, Object c, ref uint d);
  [PreserveSig()]
  int DUnadvise(uint a);
  [PreserveSig()]
  int EnumDAdvise(ref Object a);
}

And not only do the COM interfaces need importing, so do the dependent data structures, e.g. the STGMEDIUM structure:


[StructLayout(LayoutKind.Sequential)]
public struct FORMATETC {
  public CLIPFORMAT cfFormat;
  public uint ptd;
  public DVASPECT dwAspect;
  public int lindex;
  public TYMED tymed;
}

Assuming you already know how to build an Explorer extension and you have access to the COM interop goo, the actual implementation of the shell extension is normally pretty anti-climatic.

To get started building a COM-based Explorer extension in .NET, I'd first find the documentation and an example for how to do it in raw COM, then look to see if anyone's yet built the interop layer for the related interfaces and data structures. Google's Microsoft-specific search page is really good for that, and I used it to turn up a couple examples of Explorer extensions built using .NET:

  • Creating a shell extension with C#, Richard Birkby, 10/01, CodeProject.com
  • Explorer Shell Extension Technology Sample, MSDN Online


  • Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



    RELATED CONTENT
    Visual Studio .NET (Archive)
    What could be causing this problem with my add New and delete methods?
    Is there a .NET equivalent to netsend that I can use in VB.NET?
    I'm getting a lot of flickering on my application
    How can I make a VB6 network app available on the Internet using .NET?
    How can I implement an FTP upload using VB.NET?
    VB.NET app works on my local drive but not on the network drive
    In C#, how can I change the properties of controls on another form?
    How do I add images in listview by using VB.NET?
    What is the best technique for connecting to a database from VB.NET?
    How do you use control collection in VB.NET?

    Visual Studio .NET
    Load a DSL domain model instance file programmatically
    Calling via command prompt from ASP.NET
    On line-by-line analysis in VS .NET
    Best approach for merging text files using arrays
    Descriptions of symbols in the class view of a .NET solution
    What's the best approach for enumerating network resources?
    How to enable a line-by-line code walkthrough
    Changing a C++ Makefile project to a Utility project
    How can I configure Visual Studio.NET 2002 to use the .NET Framework 1.1?
    Changing a datagrid column to read-only=false based on variable

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary



    Search and Browse the Expert Answer Center
    Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
    Browse our Expert Advice



    Windows Development - White Papers, News and Expert Advice
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts