Skip to content

Latest commit

 

History

History
 
 
Shell Extension Samples

Thumbnail providers and preview handlers extend the core functionality of Windows shell.
They are different from most of the Code Pack because shell calls into your code, rather than your code calling into shell.
In order for shell to know that it needs to look for your code and find it, you must register your compiled assemblies.

To register your handlers.
1. Derive your class from IPreviewHandler, or IThumbnailProvider and one or more initialization interfaces.
2. Add the correct attributes to your handler class.
	Both Preview handlers and Thumbnail providers require these attributes.
	[ComVisible(true)] // Lets Shell/COM see your class
    [ClassInterface(ClassInterfaceType.None)] // Required
    [ProgId("HandlerSamples.XYZPreviewerWPF")] // This is required for associating the surrogate host, it should be unique per handler.
	[Guid("B9E6A036-9778-4B48-BA45-33F15B9B07AF")] // This is the GUID under which the assembly is registered; it must be unique.

	Preview handlers require this additional attribute:
	[PreviewHandler("PreviewHandlerWPFDemo", ".xyz", "{EC3E84CC-BDC5-4E9F-A67F-CC960F366497}")] // Name, Semi-colon-separated list of extensions and handler ID (must be unique).

	Thumbnail handlers require this additional attribute.
    [ThumbnailProvider("XYZThumbnailer", ".xyz", DisableProcessIsolation = false)] // Name, Semi-colon-separated list of file extensions.  DisableProcessIsolation is only required if IThumbnailFromStream is not implemented.
 3. Compile. Make sure you compile specifically for the OS version of your system.
    On 64-bit OS, build for x64.
	On 32-bit OS, build for x86.
 4. Navigate to the output directory in the Visual Studio command prompt.
	Make sure to use the correct prompt for your OS type (32/64 bit).
 5. Register your assembly using the following command, make sure to verify there were no errors.  
	If errors have occurred, you will need to recompile your assembly and register again.

	regasm /codebase "<assemblyname>"

Notes:
 - Once your assembly has been registered successfully, if it is in use by the Shell you cannot rebuild your assembly because the file is locked.
   You can either terminate the surrogate host process for the handler before rebuilding, or restart the explorer process before rebuilding.
 - Thumbnails generated by the thumbnail provider are cached.  They are regenerated for significantly different sizes.
   A cached thumbnail will be added/updated if there is no thumbnail of that or larger size, or if the file has been modified.
   To clear the cache, use the Disk Cleanup Utility and check the "Thumbnails" option.
 - To unregister an assembly, make sure the GUID is the same as originally registered, then use "regasm /unregister <assembly>".