CSShellExtIThumbnailHandler: what am I doing wrong

Oct 19, 2010 at 11:12 AM

I know this example is not available (yet), so I went ahead and try to create it based on CSShellExtIInfotipHandler. My code looks like this:

ShellExtLib.css

    #region Shell Interfaces

    [StructLayout(LayoutKind.Sequential)]
    public struct tagSIZE
    {
        public Int64 cx;
        public Int64 cy;
        public tagSIZE(Int64 x, Int64 y)
        {
            cx = x;
            cy = y;
        }
    }
   
    [ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("12004DFB-E8B1-4D60-B093-78DBB479395B")]
    internal interface IExtractImage
    {
        void Extract(System.IntPtr phBmpThumbnail);
        void GetLocation(string pszPathBuffer, uint cch, ref uint pdwPriority, ref tagSIZE prgSize, uint dwRecClrDepth, ref uint pdwFlags);
    }

    #endregion

 

FileIconExt.cs

    [ClassInterface(ClassInterfaceType.None)]
    [Guid("AE3993E5-D169-4426-A0B8-C55A01302619"), ComVisible(true)]
    public class FileIconExt : IPersistFile, IExtractImage
    {
        // The name of the selected file.
        private string filename = null;
        tagSIZE _size;

        #region IExtractImage Members

        public void Extract(System.IntPtr phBmpThumbnail)
        {
            Bitmap bmp = new Bitmap(filename);
            Bitmap bmpt = new Bitmap((int)_size.cx, (int)_size.cy);
            using (Graphics g = Graphics.FromImage(bmpt))
            {
                g.DrawImage(bmp, 0, 0, _size.cx, _size.cy);
            }
            Marshal.WriteIntPtr(phBmpThumbnail, bmpt.GetHbitmap(Color.White));
            bmp.Dispose();
            bmpt.Dispose();
        }

        public void GetLocation(string pszPathBuffer, uint cch, ref uint pdwPriority, ref tagSIZE prgSize, uint dwRecClrDepth, ref uint pdwFlags)
        {
            _size = new tagSIZE(prgSize.cx, prgSize.cy);
            pdwPriority = 0x10000000u; //normal priority
        }

        #endregion

I didnt change the regions IPersistFile and Shell Extension Registration so I left those out. To test the extension I use a png image renamed to the extension ".test1". I register this extension as following:

 

HKEY_CLASSES_ROOT\.test1\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]
@="{AE3993E5-D169-4426-A0B8-C55A01302619}"

[HKEY_CLASSES_ROOT\CLSID
@="{AE3993E5-D169-4426-A0B8-C55A01302619}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{AE3993E5-D169-4426-A0B8-C55A01302619}]
@=""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{AE3993E5-D169-4426-A0B8-C55A01302619}\InprocServer32]
@="D:\\Files\\Downloads\\Web\\ShellEx\\All-In-One Code Framework\\Visual Studio 2010\\CSShellExtIconHandler\\obj\\Debug\\CSShellExtIconHandler.dll"
"Class"="CSShellExtIconHandler.FileIconExt"
"ThreadingModel"="Apartment"

Can anyone tell me what I am doing wrong? I suspect I am not creating the interface to IExtractImage correctly.

 

Coordinator
Oct 25, 2010 at 3:55 PM

Hello

I just finished a thumbnail handler code sample by implementing the IThumbnailProvider interface (instead of the old IExtractImage interface).  Is your handler targeting Windows Vista and newer OS? If yes, the code sample may be helpful to you:

CSShellExtThumbnailHandler: http://1code.codeplex.com/SourceControl/changeset/view/56349#1344566

VBShellExtThumbnailHandler: http://1code.codeplex.com/SourceControl/changeset/view/56349#1345031

Feb 21, 2011 at 7:52 AM

Sorry to ask in this old thread, but do you plan to implement thumbnail extension handler that Implements IExtractImage[2] interface?