Getting thumbnails RRS feed

  • Question

  • Hello

    I'm trying to get a thumbnail for a file. I want to use explorer as this is the way third party developers add thumbnail handlers. I have been searching for a solution for quite some time but I'm baffled that I can't find a single source where this is implemented. There's no dll that I can just use and it works. Instead I have to wrap a huge number of win32 calls. Something that gets even more troublesome because vista has a different method for doing this than xp. On Linux Mono has wrapped the gnome functions for creating thumbnails quite nicely so I was quite shocked to find this so hard to do in Windows.

    Enough ranting. It appears that in XP I have to use IExtractImage and in Vista it's better to use IThumbnailCache. Firstly I just wanted to get IExtractImage working as that should work with both XP and Vista. I found some code that should implement this but I get the following exception when I try to extract the thumbnail using it:

    threw the following exception:'Specified cast is not valid.' ---> System.InvalidCastException: Specified cast is not valid.

                szPath = new StringBuilder(260);
                EIEIFLAG f = (EIEIFLAG)flags;
                ie.GetLocation(szPath, 260, ref priority, ref sz, requestedColourDepth, ref f);
                pIconLarge = ie.Extract();

    I get that exception in the call to ie.Extract();

    Does anyone have a solution? I found that microsoft released some code that makes it easier to create a thumbnail provider in .net, but it didn't wrap extracting thumbnail.

    I've tried googling this a couple of times but there's almost no working code. I have tried the code from here, but it doesn't work:


    Any tips?

    Thursday, April 24, 2008 3:19 PM

All replies

  • I found this blog posts that deals with generating thumbnails in vista, seems to work pretty nice:

    Thursday, April 24, 2008 4:19 PM