Author |
Message |
Andrea N.
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Hi, My application creates nice graphics see http://www.mavericksplan.com/mavericks and it saves a custom document type. I'd like to show the contet of the document in Explorer when the user switch to Thumbnail view.
To implement this feature I understand I need to create a Shell Extension Handler Thumbnail Extractor that extract the image from my file type to feed Explorer thumbnail vew, which is not easy at all for me.
I look on the web and I found 1 C++ example and none in C#.
Does anybody have a sample code to create a Shell Extension Handler thumbnail extractor with .net in C#
Thank you Andrea
.NET Development15
|
|
|
|
|
Jesse Kaplan
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Unfortunately unmanaged C++ is really the only way to go here.
Writing in-process \shell extensions in managed code is actually a very dangerous thing to do because it has the effect of injecting your managed code (and the .NET Framework) into every application on the machine that has a file open dialog.
The problems occur because only one version of the .NET Framework can be loaded in a process at any given time (other shared components such as java and msxml have the same property and thus the same restriction).
If you write your shell extension using the 2.0 .NET Framework and an application built with the 1.1 .NET Framework uses a file open dialog, your shell extension will fail because it can not run on an earlier version. Things can get even worse if your shell-extension manages to get loaded in a process before another applications managed code does: your extension may force an existing application onto a different runtime version than the one it was expecting and cause it to fail.
Because of these problems we strongly recomend against using any single-instance-per-process runtime or library (such as the .NET Framework, java, or msxml) in an in-process shell extension.
|
|
|
|
|
Andrea N.
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Thank you Jesse. I will go with unmanaged code then.
I'm positive I will not be able to create a bug free code at first, how bad is going to be for my Explorer and Windows I mean can I break it having really hard time in restoring it or cleaning it
Thanks again Andrea
|
|
|
|
|
Andrey Titov
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Do not believe to Jesse! It is possible to create Shell Extensions with managed code.
See this example:
<SDK v1.1>\Samples\Technologies\Interop\Applications\ShellCmd\
|
|
|
|
|
Andrea N.
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Thank you Andrey, You are right! The sample is called "CLR Explorer Shell Extension Sample"
I'm going to look if I can figure how to define the Thumbnail view.
Andrea
|
|
|
|
|
Telesto
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Correct me if im wrong, but jesse is not saying it cant be done, he is saying that it is a dangerous thing to do.
|
|
|
|
|
Jesse Kaplan
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Telestoon is correct here. It is certainly possible to create these shell extensions with .NET but it is extremely dangerous to do.
It's not that if you have a bug in the application you can cause instability problems in exporer.exe (though that is important as well). The real issue is that when you write shell extensions you actually inject your code and your depenencies (such as a particular version of the .net framework) inside all processes on the machine that have an open file dialog box. If the application that does an open file uses a different version of the runtime than the one your extension was built against any number of bad things can happen.
|
|
|
|
|
Rowland
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
I don't think it's that bad a thing to do -- after all, Microsoft
have released a shell extension to display thumbnails from digital
camarea raw images; and it is written in .Net 1.1
|
|
|
|
|
JonathanPerret
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Jesse, assuming one did not need the shell extension to be loaded into non-Explorer processes, one could always write an unmanaged COM shim (as is commonly done for managed Office add-ins) that would check that the loading process is EXPLORER.EXE before loading the actual (managed) extension, right
|
|
|
|
|
Raymond Chen - MSFT
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
That's still wrong. What happens when Explorer becomes written in managed code with a conflicting CLR version from your shell extension
|
|
|
|
|
JonathanPerret
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Thank you for your insight, Raymond.
I would like however to point out that the very same potential problem exists for managed Office add-ins. You didn't mention another one : that various managed extensions could conflict if each tried to load a specific version of the CLR. I believe these issues can be mostly avoided if each extension is modest in its requirements, i.e. :
- be compiled against the oldest CLR version possible
- if the CLR is already loaded in the process, use it
- if the CLR is not loaded, load the latest version available (the default behavior of the hosting API)
The CLR team's stellar work in backwards compatibility does the rest...
Cheers, --Jonathan
|
|
|
|
|
Raymond Chen - MSFT
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
If the CLR is not loaded, you can still run into trouble if you load the latest version available, because the application might use the CLR on-demand (i.e., not load the CLR until you invoke a feature that requires it). That feature might have been written to an older version of the CLR, and loading the latest version would create a conflict. (I don't know if the CLR hosting APIs help here any, but you can't count on people using it - I bet most people haven't even heard of CLR hosting.)
|
|
|
|
|
Mladen Mihajlovic
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
|
|
|
nobugz
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
Extending that logic, wouldn't the same be true for any COM visible component written in .NET
|
|
|
|
|
Raymond Chen - MSFT
|
Posted: .NET Base Class Library, Create a Shell Extension Handler thumbnail extractor with .net? |
Top |
The key point is that you have to avoid injecting the CLR into processes that aren't expecting it. COM is just a conduit for the injection. Don't focus on the COM part; focus on the injection part. If all the processes that use your COM object are expecting the CLR (e.g. because you wrote them) then there's no problem since there is no injection.
|
|
|
|
|
|