1

i've written a shell extension in C# which shows my own context menu entry (FileExtensionMenu) After clicking my menu entry the shell extension should submit the choosen file name to my main application that it can process with this file.

My question is which is the way to communicate between the extension and the application. Or must i transfer the program logic to the shell extension code?

Thanks in advance for your help

Action Heinz
  • 722
  • 10
  • 23
  • 1
    You can do this without a shell extension, just add a file association. Which would be the "preferred way". – Hans Passant Apr 17 '13 at 10:17
  • Please read [this](http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx) and [this](http://blogs.msdn.com/b/oldnewthing/archive/2013/02/22/10396079.aspx) on why this is a bad idea (although some [disagree](http://stackoverflow.com/questions/15834410/regasm-codebase-works-but-file-generated-with-regasm-codebase-regfile-does-no/15835909#comment22533300_15835909) ). – Euro Micelli Apr 18 '13 at 12:14

1 Answers1

2

You can use Windows Communication Foundation (WCF) to call methods in your running application. It's somewhat fiddly to set up, but once you have it makes it very easy to call methods via RPC.

Note that the methods are called from a separate thread, so you'd need to marshal it to the UI calls if necessary (using Control.Invoke() or Control.BeginInvoke() for Windows Forms).

See here for full details.

Also, see here for a simple example. As Adam says below, you will need to use named pipes as the transport mechanism, so when looking at that example bear in mind that instead of

new NetTcpBinding(),
"net.tcp://localhost:8000");

you will have something like:

new NetNamedPipeBinding(),
"net.pipe://localhost/YourServiceNameGoesHere"
Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • 2
    Specifically the OP needs to use named pipes (the successor to IPC in .NET Remoting): http://stackoverflow.com/questions/1613586/c-sharp-wcf-inter-process-communication – Adam Houldsworth Apr 17 '13 at 09:36