views:

207

answers:

2

Hi, i have a question, after allot of hours in googling and reading articles, i understood that namespace extenssion in windows is quite tricky (In C++ at least), now i've also seen its possible to do so in C# , but microsft does'nt officaly confirms using .net for namespace extensions... though i have seen very nice commercial Namespace Extenssion framework , but none is free....

so to my question :) , i want to develop my own Namespace Extenssion ,i have C++/C# knwoledge and basic COM/ATL , but if it can be done i prefer c#, so does c# inteop can fully do the work without too many tricks ? or one shall go diving in the ATL to create the neccessary COM objects...

thanks!

+4  A: 

In general, up 'til now, it's been a bad idea to write a shell extension in managed code. A process only loads one version of the CLR and if someone else picked a different version first, bang, you're dead.

This may be changing in the near future, but at this point stick with native code for your shell extension.

Greg D
i only want explorer.exe to load the extension so i'll go with c# and i will pay the price for .net 1.x apps that could not show my extension...
_Avishay_
+2  A: 

EDIT: Here's some official words on the subject:

http://msdn.microsoft.com/en-us/magazine/ee819091.aspx

Note the very precise information about how code targeting 2.x and later can coexist with 4.0 inside the same process. So although SxS is a 4.0 feature, it has benefits for 2.x users.

However, there is this stipulation:

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. We still do not support writing shell extensions using any version earlier than .NET Framework 4 because those versions of the runtime do not load in-process with one another and will cause failures in many cases.

So there's an extra problem: the explorer.exe process isn't the only process that hosts shell extensions. Any program that has the File Open dialog may need to load shell extensions. So your .NET 2.0-3.5 extensions would fail to load within any .NET 1.x application's File Open dialog. It's going to be a similar story with things like the GUI components of printer drivers, which also load into any application that shows the standard Printer dialog.

Therefore, if you want to develop a managed shell extension, VS2010 is the place to start.

Daniel Earwicker
[A] i understand targeting to .net 2.0 and up is secure ? [1] i dont think targeting 4.0 is wise , im thinking targeting 2.0 to be more compatible.. ? [2] the SxS is only 4.0 feature
_Avishay_
@Avishay - I updated my answer, I forgot the part about shell extensions loading into random processes. But targeting 2.x doesn't make you any more "compatible". If a user has XP, they'll need to download the framework. If they have Vista, they'll need to upgrade to 3.5. And 4.0 is just around the corner. Seriously, you could start working on a C++ shell extension now and by the time you've got the bugs out of it, everyone else will be using C# to do the same thing more easily.
Daniel Earwicker
Daniel: what is the price that .NET 1.x application will not succeed opening the requested extension ? will the process crush ? will the extension be un-loaded ? because if its just a failure of the process of some gui printer , etc i'm willing to pay the price and let my extension be visible to .net 2.0+ apps....
_Avishay_
I'm not sure - but I suspect that 2.x will refuse to load, and so the explorer code in the File Open dialog will get back an error from `CoCreateInstance`, and *should* just act like the extension is not installed. That is the most likely result. But it's just my reasoning, not something I've tried. NB. the printer GUI example is unrelated to shell namespace extensions, that was just another example of a way that a DLL can be written such that many thousands of different .NET apps will "accidentally" load it.
Daniel Earwicker
how come that explorer.exe will get the error ? as i understood the problem occurs if a process , for instance explorer.exe tries to load different add-ins (extension) which caused him to load the add-in in .net 1.x clr,and then afterwards my extension which is .net 2.0 comes after and will be loaded in the .net 1.x clr,then there is a problem... BUT if nothing in explorer.exe will cause him to load .net 1.x clr nothing should be breaked.... am i right ? :)
_Avishay_
No, explorer.exe as a distinct process will not have a problem loading only 2.x extensions as long as there are no 1.x extensions installed. But there are components of Windows Explorer that are used in the File Open dialog used by thousands of applications. Some of those applications are NET 1.x applications. So the 1.x runtime is already loaded for those applications, and so your 2.x extension will not load... I think you already got this point from your previous comment ("what is the price that .NET 1.x application will not succeed...").
Daniel Earwicker
yes i did get the point, but you made me hesitate again with the last answer ;) anyway i'm willing to pay the price for the .net 1.x apps as long as explorer.exe runs my extension im fine. anyway 10x for the interesting info about SxS in clr 4 too ! :)
_Avishay_