Results 1 to 15 of 15

Thread: [2008] Using Shell's IExtractImage to extract file thumbnail

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    [2008] Using Shell's IExtractImage to extract file thumbnail

    Can someone please show me how to use Shell's IExtractImage to get the thumbnail from a non-image file ?

    MSDN coverage is thin with no sample code.
    There is some delphi code which I cannot translate to vb.net.
    Then there is the perfect VB project which I can't get to work in vb.net

    Windows Explorer is able to show us thumbnails of files like powerpoint, mpegs and avis.

    How can I mimic that in vb.net
    Last edited by Xancholy; Jun 17th, 2008 at 07:50 PM.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    I found some C#code here but I can't seem to translate it to vb.net. Can anyone please help ? Here's part 1:
    Code:
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;
    
    public class ShellThumbnail : IDisposable
    {
    
      [Flags]
        private enum ESTRRET
      {
        STRRET_WSTR = 0,
        STRRET_OFFSET = 1,
        STRRET_CSTR = 2
      }
    
      [Flags]
        private enum ESHCONTF
      {
        SHCONTF_FOLDERS = 32,
        SHCONTF_NONFOLDERS = 64,
        SHCONTF_INCLUDEHIDDEN = 128,
      }
    
      [Flags]
        private enum ESHGDN
      {
        SHGDN_NORMAL = 0,
        SHGDN_INFOLDER = 1,
        SHGDN_FORADDRESSBAR = 16384,
        SHGDN_FORPARSING = 32768
      }
    
      [Flags]
        private enum ESFGAO
      {
        SFGAO_CANCOPY = 1,
        SFGAO_CANMOVE = 2,
        SFGAO_CANLINK = 4,
        SFGAO_CANRENAME = 16,
        SFGAO_CANDELETE = 32,
        SFGAO_HASPROPSHEET = 64,
        SFGAO_DROPTARGET = 256,
        SFGAO_CAPABILITYMASK = 375,
        SFGAO_LINK = 65536,
        SFGAO_SHARE = 131072,
        SFGAO_READONLY = 262144,
        SFGAO_GHOSTED = 524288,
        SFGAO_DISPLAYATTRMASK = 983040,
        SFGAO_FILESYSANCESTOR = 268435456,
        SFGAO_FOLDER = 536870912,
        SFGAO_FILESYSTEM = 1073741824,
        SFGAO_HASSUBFOLDER = -2147483648,
        SFGAO_CONTENTSMASK = -2147483648,
        SFGAO_VALIDATE = 16777216,
        SFGAO_REMOVABLE = 33554432,
        SFGAO_COMPRESSED = 67108864,
      }
    
      private enum EIEIFLAG
      {
        IEIFLAG_ASYNC = 1,
        IEIFLAG_CACHE = 2,
        IEIFLAG_ASPECT = 4,
        IEIFLAG_OFFLINE = 8,
        IEIFLAG_GLEAM = 16,
        IEIFLAG_SCREEN = 32,
        IEIFLAG_ORIGSIZE = 64,
        IEIFLAG_NOSTAMP = 128,
        IEIFLAG_NOBORDER = 256,
        IEIFLAG_QUALITY = 512
      }
    
      [StructLayout(LayoutKind.Sequential, Pack=4, Size=0, CharSet=CharSet.Auto)]
        private struct STRRET_CSTR
      {
        public ESTRRET uType;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=520)]
        public byte[] cStr;
      }
    
      [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Auto)]
      private struct STRRET_ANY
      {
        [FieldOffset(0)]
        public ESTRRET uType;
        [FieldOffset(4)]
        public IntPtr pOLEString;
      }
      [StructLayoutAttribute(LayoutKind.Sequential)]
      private struct SIZE
      {
        public int cx;
        public int cy;
      }
     
      [ComImport(), Guid("00000000-0000-0000-C000-000000000046")]
      [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
      private interface IUnknown
      {
    
        [PreserveSig()]
        IntPtr QueryInterface(ref Guid riid, ref IntPtr pVoid);
    
        [PreserveSig()]
        IntPtr AddRef();
    
        [PreserveSig()]
        IntPtr Release();
      }
     
      [ComImportAttribute()]
      [GuidAttribute("00000002-0000-0000-C000-000000000046")]
      [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
      private interface IMalloc
      {
    
        [PreserveSig()]
        IntPtr Alloc(int cb);
    
        [PreserveSig()]
        IntPtr Realloc(IntPtr pv, int cb);
    
        [PreserveSig()]
        void Free(IntPtr pv);
    
        [PreserveSig()]
        int GetSize(IntPtr pv);
    
        [PreserveSig()]
        int DidAlloc(IntPtr pv);
    
        [PreserveSig()]
        void HeapMinimize();
      }
     
      [ComImportAttribute()]
      [GuidAttribute("000214F2-0000-0000-C000-000000000046")]
      [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
      private interface IEnumIDList
      {
    
        [PreserveSig()]
        int Next(int celt, ref IntPtr rgelt, ref int pceltFetched);
    
        void Skip(int celt);
    
        void Reset();
    
        void Clone(ref IEnumIDList ppenum);
      }
     
      [ComImportAttribute()]
      [GuidAttribute("000214E6-0000-0000-C000-000000000046")]
      [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
      private interface IShellFolder
      {
    
        void ParseDisplayName(IntPtr hwndOwner, IntPtr pbcReserved,    
          [MarshalAs(UnmanagedType.LPWStr)]string lpszDisplayName,
          ref int pchEaten, ref IntPtr ppidl, ref int pdwAttributes);
    
        void EnumObjects(IntPtr hwndOwner,    
          [MarshalAs(UnmanagedType.U4)]ESHCONTF grfFlags,
          ref IEnumIDList ppenumIDList);
    
        void BindToObject(IntPtr pidl, IntPtr pbcReserved, ref Guid riid,
          ref IShellFolder ppvOut);
    
        void BindToStorage(IntPtr pidl, IntPtr pbcReserved, ref Guid riid, IntPtr ppvObj);
    
        [PreserveSig()]
        int CompareIDs(IntPtr lParam, IntPtr pidl1, IntPtr pidl2);
    
        void CreateViewObject(IntPtr hwndOwner, ref Guid riid,
          IntPtr ppvOut);
    
        void GetAttributesOf(int cidl, IntPtr apidl,    
          [MarshalAs(UnmanagedType.U4)]ref ESFGAO rgfInOut);
    
        void GetUIObjectOf(IntPtr hwndOwner, int cidl, ref IntPtr apidl, ref Guid riid, ref int prgfInOut, ref IUnknown ppvOut);
    
        void GetDisplayNameOf(IntPtr pidl,    
          [MarshalAs(UnmanagedType.U4)]ESHGDN uFlags,
          ref STRRET_CSTR lpName);
    
        void SetNameOf(IntPtr hwndOwner, IntPtr pidl,    
          [MarshalAs(UnmanagedType.LPWStr)]string lpszName,    
          [MarshalAs(UnmanagedType.U4)] ESHCONTF uFlags,
          ref IntPtr ppidlOut);
      }
      [ComImportAttribute(), GuidAttribute("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
      private interface IExtractImage
      {
        void GetLocation( [Out(), MarshalAs(UnmanagedType.LPWStr)]
          StringBuilder pszPathBuffer, int cch, ref int pdwPriority, ref SIZE prgSize, int dwRecClrDepth, ref int pdwFlags);
    
        void Extract(ref IntPtr phBmpThumbnail);
      }
    
      private class UnmanagedMethods
      {
    
        [DllImport("shell32", CharSet=CharSet.Auto)]
        internal extern static int SHGetMalloc(ref IMalloc ppMalloc);
    
        [DllImport("shell32", CharSet=CharSet.Auto)]
        internal extern static int SHGetDesktopFolder(ref IShellFolder ppshf);
    
        [DllImport("shell32", CharSet=CharSet.Auto)]
        internal extern static int SHGetPathFromIDList(IntPtr pidl, StringBuilder pszPath);
    
        [DllImport("gdi32", CharSet=CharSet.Auto)]
        internal extern static int DeleteObject(IntPtr hObject);
    
      }
    
      ~ShellThumbnail()
      {
        Dispose();
      }
    
      private IMalloc alloc = null;
      private bool disposed = false;
      private Size _desiredSize = new Size(100, 100);
      private Bitmap _thumbNail;
    
      public Bitmap ThumbNail
      {
        get
        {
          return _thumbNail;
        }
      }
    
      public Size DesiredSize
      {
        get { return _desiredSize; }
        set { _desiredSize = value; }
      }

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Here's part 2:
    Code:
    private IMalloc Allocator
      {
        get
        {
          if (!disposed)
          {
            if (alloc == null)
            {
              UnmanagedMethods.SHGetMalloc(ref alloc);
            }
          }
          else
          {
            Debug.Assert(false, "Object has been disposed.");
          }
          return alloc;
        }
      }
    
      public Bitmap GetThumbnail(string fileName)
      {
        if (!File.Exists(fileName) && !Directory.Exists(fileName))
        {
          throw new FileNotFoundException(string.Format("The file '{0}' does not exist", fileName), fileName);
        }
        if (_thumbNail != null)
        {
          _thumbNail.Dispose();
          _thumbNail = null;
        }
        IShellFolder folder = null;
        try
        {
          folder = getDesktopFolder;
        }
        catch (Exception ex)
        {
          throw ex;
        }
        if (folder != null)
        {
          IntPtr pidlMain = IntPtr.Zero;
          try
          {
            int cParsed = 0;
            int pdwAttrib = 0;
            string filePath = Path.GetDirectoryName(fileName);
            folder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, filePath, ref cParsed, ref pidlMain, ref pdwAttrib);
          }
          catch (Exception ex)
          {
            Marshal.ReleaseComObject(folder);
            throw ex;
          }
          if (pidlMain != IntPtr.Zero)
          {
            Guid iidShellFolder = new Guid("000214E6-0000-0000-C000-000000000046");
            IShellFolder item = null;
            try
            {
              folder.BindToObject(pidlMain, IntPtr.Zero, ref iidShellFolder, ref item);
            }
            catch (Exception ex)
            {
              Marshal.ReleaseComObject(folder);
              Allocator.Free(pidlMain);
              throw ex;
            }
            if (item != null)
            {
              IEnumIDList idEnum = null;
              try
              {
                item.EnumObjects(IntPtr.Zero, (ESHCONTF.SHCONTF_FOLDERS | ESHCONTF.SHCONTF_NONFOLDERS), ref idEnum);
              }
              catch (Exception ex)
              {
                Marshal.ReleaseComObject(folder);
                Allocator.Free(pidlMain);
                throw ex;
              }
              if (idEnum != null)
              {
                int hRes = 0;
                IntPtr pidl = IntPtr.Zero;
                int fetched = 0;
                bool complete = false;
                while (!complete)
                {
                  hRes = idEnum.Next(1, ref pidl, ref fetched);
                  if (hRes != 0)
                  {
                    pidl = IntPtr.Zero;
                    complete = true;
                  }
                  else
                  {
                    if (_getThumbNail(fileName, pidl, item))
                    {
                      complete = true;
                    }
                  }
                  if (pidl != IntPtr.Zero)
                  {
                    Allocator.Free(pidl);
                  }
                }
                Marshal.ReleaseComObject(idEnum);
              }
              Marshal.ReleaseComObject(item);
            }
            Allocator.Free(pidlMain);
          }
          Marshal.ReleaseComObject(folder);
        }
        return ThumbNail;
      }
    
      private bool _getThumbNail(string file, IntPtr pidl, IShellFolder item)
      {
        IntPtr hBmp = IntPtr.Zero;
        IExtractImage extractImage = null;
        try
        {
          string pidlPath = PathFromPidl(pidl);
          if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
          {
            IUnknown iunk = null;
            int prgf = 0;
            Guid iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
            item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, ref prgf, ref iunk);
            extractImage = (IExtractImage)iunk;
            if (extractImage != null)
            {
              Console.WriteLine("Got an IExtractImage object!");
              SIZE sz = new SIZE();
              sz.cx = DesiredSize.Width;
              sz.cy = DesiredSize.Height;
              StringBuilder location = new StringBuilder(260, 260);
              int priority = 0;
              int requestedColourDepth = 32;
              EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
              int uFlags = (int)flags;
              extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
              extractImage.Extract(ref hBmp);
              if (hBmp != IntPtr.Zero)
              {
                _thumbNail = Bitmap.FromHbitmap(hBmp);
              }
              Marshal.ReleaseComObject(extractImage);
              extractImage = null;
            }
            return true;
          }
          else
          {
            return false;
          }
        }
        catch (Exception ex)
        {
          if (hBmp != IntPtr.Zero)
          {
            UnmanagedMethods.DeleteObject(hBmp);
          }
          if (extractImage != null)
          {
            Marshal.ReleaseComObject(extractImage);
          }
          throw ex;
        }
      }
    
      private string PathFromPidl(IntPtr pidl)
      {
        StringBuilder path = new StringBuilder(260, 260);
        int result = UnmanagedMethods.SHGetPathFromIDList(pidl, path);
        if (result == 0)
        {
          return string.Empty;
        }
        else
        {
          return path.ToString();
        }
      }
    
      private IShellFolder getDesktopFolder
      {
        get
        {
          IShellFolder ppshf = null;
          int r = UnmanagedMethods.SHGetDesktopFolder(ref ppshf);
          return ppshf;
        }
      }
    
      public void Dispose()
      {
        if (!disposed)
        {
          if (alloc != null)
          {
            Marshal.ReleaseComObject(alloc);
          }
          alloc = null;
          if (_thumbNail != null)
          {
            _thumbNail.Dispose();
          }
          disposed = true;
        }
      }
    
    }

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Then I found this on pinvoke

    Code:
    <ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1")> _
    Public Interface IExtractImage
          ' Methods
        Sub GetLocation( _
            <Out, MarshalAs(UnmanagedType.LPWStr)> ByVal pszPathBuffer As String, _
            ByVal cch As Integer, _
            ByRef pdwPriority As Integer, _
            ByRef prgSize As SIZE, _
            ByVal dwRecClrDepth As Integer, _
            ByRef pdwFlags As Integer)
        Sub Extract( _
            <Out> ByRef phBmpThumbnail As IntPtr)
    End Interface

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    anyone ?

  6. #6
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    I used a conversion tool so I am not sure that it will run. I'll send you the next one in a few minutes
    Code:
    view plain sourcecopy to clipboard
    Imports System 
    Imports System.Diagnostics 
    Imports System.Drawing 
    Imports System.IO 
    Imports System.Runtime.InteropServices 
    Imports System.Text 
    
    Public Class ShellThumbnail 
        Implements IDisposable 
        
        <Flags()> _ 
        Private Enum ESTRRET 
            STRRET_WSTR = 0 
            STRRET_OFFSET = 1 
            STRRET_CSTR = 2 
        End Enum 
        
        <Flags()> _ 
        Private Enum ESHCONTF 
            SHCONTF_FOLDERS = 32 
            SHCONTF_NONFOLDERS = 64 
            SHCONTF_INCLUDEHIDDEN = 128 
        End Enum 
        
        <Flags()> _ 
        Private Enum ESHGDN 
            SHGDN_NORMAL = 0 
            SHGDN_INFOLDER = 1 
            SHGDN_FORADDRESSBAR = 16384 
            SHGDN_FORPARSING = 32768 
        End Enum 
        
        <Flags()> _ 
        Private Enum ESFGAO 
            SFGAO_CANCOPY = 1 
            SFGAO_CANMOVE = 2 
            SFGAO_CANLINK = 4 
            SFGAO_CANRENAME = 16 
            SFGAO_CANDELETE = 32 
            SFGAO_HASPROPSHEET = 64 
            SFGAO_DROPTARGET = 256 
            SFGAO_CAPABILITYMASK = 375 
            SFGAO_LINK = 65536 
            SFGAO_SHARE = 131072 
            SFGAO_READONLY = 262144 
            SFGAO_GHOSTED = 524288 
            SFGAO_DISPLAYATTRMASK = 983040 
            SFGAO_FILESYSANCESTOR = 268435456 
            SFGAO_FOLDER = 536870912 
            SFGAO_FILESYSTEM = 1073741824 
            SFGAO_HASSUBFOLDER = -2147483648 
            SFGAO_CONTENTSMASK = -2147483648 
            SFGAO_VALIDATE = 16777216 
            SFGAO_REMOVABLE = 33554432 
            SFGAO_COMPRESSED = 67108864 
        End Enum 
        
        Private Enum EIEIFLAG 
            IEIFLAG_ASYNC = 1 
            IEIFLAG_CACHE = 2 
            IEIFLAG_ASPECT = 4 
            IEIFLAG_OFFLINE = 8 
            IEIFLAG_GLEAM = 16 
            IEIFLAG_SCREEN = 32 
            IEIFLAG_ORIGSIZE = 64 
            IEIFLAG_NOSTAMP = 128 
            IEIFLAG_NOBORDER = 256 
            IEIFLAG_QUALITY = 512 
        End Enum 
        
        <StructLayout(LayoutKind.Sequential, Pack := 4, Size := 0, CharSet := CharSet.Auto)> _ 
        Private Structure STRRET_CSTR 
            Public uType As ESTRRET 
            <MarshalAs(UnmanagedType.ByValArray, SizeConst := 520)> _ 
            Public [cStr] As Byte() 
        End Structure 
        
        <StructLayout(LayoutKind.Explicit, CharSet := CharSet.Auto)> _ 
        Private Structure STRRET_ANY 
            <FieldOffset(0)> _ 
            Public uType As ESTRRET 
            <FieldOffset(4)> _ 
            Public pOLEString As IntPtr 
        End Structure 
        <StructLayoutAttribute(LayoutKind.Sequential)> _ 
        Private Structure SIZE 
            Public cx As Integer 
            Public cy As Integer 
        End Structure 
        
        <ComImport(), Guid("00000000-0000-0000-C000-000000000046")> _ 
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _ 
        Private Interface IUnknown 
            
            <PreserveSig()> _ 
            Function QueryInterface(ByRef riid As Guid, ByRef pVoid As IntPtr) As IntPtr 
            
            <PreserveSig()> _ 
            Function AddRef() As IntPtr 
            
            <PreserveSig()> _ 
            Function Release() As IntPtr 
        End Interface 
        
        <ComImportAttribute()> _ 
        <GuidAttribute("00000002-0000-0000-C000-000000000046")> _ 
        <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ 
        Private Interface IMalloc 
            
            <PreserveSig()> _ 
            Function Alloc(ByVal cb As Integer) As IntPtr 
            
            <PreserveSig()> _ 
            Function Realloc(ByVal pv As IntPtr, ByVal cb As Integer) As IntPtr 
            
            <PreserveSig()> _ 
            Sub Free(ByVal pv As IntPtr) 
            
            <PreserveSig()> _ 
            Function GetSize(ByVal pv As IntPtr) As Integer 
            
            <PreserveSig()> _ 
            Function DidAlloc(ByVal pv As IntPtr) As Integer 
            
            <PreserveSig()> _ 
            Sub HeapMinimize() 
        End Interface 
        
        <ComImportAttribute()> _ 
        <GuidAttribute("000214F2-0000-0000-C000-000000000046")> _ 
        <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ 
        Private Interface IEnumIDList 
            
            <PreserveSig()> _ 
            Function [Next](ByVal celt As Integer, ByRef rgelt As IntPtr, ByRef pceltFetched As Integer) As Integer 
            
            Sub Skip(ByVal celt As Integer) 
            
            Sub Reset() 
            
            Sub Clone(ByRef ppenum As IEnumIDList) 
        End Interface 
        
        <ComImportAttribute()> _ 
        <GuidAttribute("000214E6-0000-0000-C000-000000000046")> _ 
        <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ 
        Private Interface IShellFolder 
            
            Sub ParseDisplayName(ByVal hwndOwner As IntPtr, ByVal pbcReserved As IntPtr,         <MarshalAs(UnmanagedType.LPWStr)> _ 
    ByVal lpszDisplayName As String, ByRef pchEaten As Integer, ByRef ppidl As IntPtr, ByRef pdwAttributes As Integer) 
            
            Sub EnumObjects(ByVal hwndOwner As IntPtr,         <MarshalAs(UnmanagedType.U4)> _ 
    ByVal grfFlags As ESHCONTF, ByRef ppenumIDList As IEnumIDList) 
            
            Sub BindToObject(ByVal pidl As IntPtr, ByVal pbcReserved As IntPtr, ByRef riid As Guid, ByRef ppvOut As IShellFolder) 
            
            Sub BindToStorage(ByVal pidl As IntPtr, ByVal pbcReserved As IntPtr, ByRef riid As Guid, ByVal ppvObj As IntPtr) 
            
            <PreserveSig()> _ 
            Function CompareIDs(ByVal lParam As IntPtr, ByVal pidl1 As IntPtr, ByVal pidl2 As IntPtr) As Integer 
            
            Sub CreateViewObject(ByVal hwndOwner As IntPtr, ByRef riid As Guid, ByVal ppvOut As IntPtr) 
            
            Sub GetAttributesOf(ByVal cidl As Integer, ByVal apidl As IntPtr,         <MarshalAs(UnmanagedType.U4)> _ 
    ByRef rgfInOut As ESFGAO) 
            
            Sub GetUIObjectOf(ByVal hwndOwner As IntPtr, ByVal cidl As Integer, ByRef apidl As IntPtr, ByRef riid As Guid, ByRef prgfInOut As Integer, ByRef ppvOut As IUnknown) 
            
            Sub GetDisplayNameOf(ByVal pidl As IntPtr,         <MarshalAs(UnmanagedType.U4)> _ 
    ByVal uFlags As ESHGDN, ByRef lpName As STRRET_CSTR) 
            
            Sub SetNameOf(ByVal hwndOwner As IntPtr, ByVal pidl As IntPtr,         <MarshalAs(UnmanagedType.LPWStr)> _ 
    ByVal lpszName As String,         <MarshalAs(UnmanagedType.U4)> _ 
    ByVal uFlags As ESHCONTF, ByRef ppidlOut As IntPtr) 
        End Interface 
        <ComImportAttribute(), GuidAttribute("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ 
        Private Interface IExtractImage 
            Sub GetLocation(        <Out(), MarshalAs(UnmanagedType.LPWStr)> _ 
    ByVal pszPathBuffer As StringBuilder, ByVal cch As Integer, ByRef pdwPriority As Integer, ByRef prgSize As SIZE, ByVal dwRecClrDepth As Integer, ByRef pdwFlags As Integer) 
            
            Sub Extract(ByRef phBmpThumbnail As IntPtr) 
        End Interface 
        
        Private Class UnmanagedMethods 
            
            <DllImport("shell32", CharSet := CharSet.Auto)> _ 
            Friend Shared Function SHGetMalloc(ByRef ppMalloc As IMalloc) As Integer 
            End Function 
            
            <DllImport("shell32", CharSet := CharSet.Auto)> _ 
            Friend Shared Function SHGetDesktopFolder(ByRef ppshf As IShellFolder) As Integer 
            End Function 
            
            <DllImport("shell32", CharSet := CharSet.Auto)> _ 
            Friend Shared Function SHGetPathFromIDList(ByVal pidl As IntPtr, ByVal pszPath As StringBuilder) As Integer 
            End Function 
            
            <DllImport("gdi32", CharSet := CharSet.Auto)> _ 
            Friend Shared Function DeleteObject(ByVal hObject As IntPtr) As Integer 
            End Function 
            
        End Class 
        Protected Overrides Sub Finalize() 
            Try 
                
                Dispose() 
            Finally 
                MyBase.Finalize() 
            End Try 
        End Sub 
        
        Private alloc As IMalloc = Nothing 
        Private disposed As Boolean = False 
        Private _desiredSize As New Size(100, 100) 
        Private _thumbNail As Bitmap 
        
        Public ReadOnly Property ThumbNail() As Bitmap 
            Get 
                Return _thumbNail 
            End Get 
        End Property 
        
        Public Property DesiredSize() As Size 
            Get 
                Return _desiredSize 
            End Get 
            Set 
                _desiredSize = value 
            End Set 
        End Property 
    End Class
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    You can simply compile the C# code to a class library and use it in your VB.net project.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Clanguage, thanks for the conversion. Nope it doesn't work. Can anyone who knows more than me please go through this code to see if it can be salvaged ?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Quote Originally Posted by stanav
    You can simply compile the C# code to a class library and use it in your VB.net project.
    I haven't done this before. Can you point me to a walk-thru ? Thanks

  10. #10
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Quote Originally Posted by stanav
    You can simply compile the C# code to a class library and use it in your VB.net project.
    Better yet unless the code is buggy. If it comes from a reputable site then it should be ok.
    By the way the converter is balking at the Allocator and refuses to convert.
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Quote Originally Posted by Clanguage
    By the way the converter is balking at the Allocator and refuses to convert.
    I know ! I've tried it

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Quote Originally Posted by Xancholy
    I haven't done this before. Can you point me to a walk-thru ? Thanks
    1. You create a new project, choose C# as the language, and choose Class Library from the templates shown. Give your project a name.
    2. Copy the C# code and paste it in your project. Rename the class name as you like.
    3. Build the project. If the compiler complaining on any missing references, add them, then rebuild.
    4. Once the build is successful, you have a dll sitting in the bin\Release folder of that project ready to be used.

    Now back to your VB project, you add reference and browser to the newly created dll. After added, the new dll is ready for you to use in your VB project.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  13. #13
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    I've tested out the C# code (compiled to a dll and use it in a VB project). It can only extract thumbnail from image files (jpg), image folders (contains jpg files), and videos (wmv). I didn't test with different image types (bmp, gif, png...) or video types (avi, mpeg,...) since I'm at work, and the work computer doesn't store alot of multimedia files.
    It fails to extract thumbnails for pdf files. If a folder has no images in it, it will also fail.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    Drat.Thanks for testing it. I was hoping it would get thumbnails for all
    image types
    video types
    & powerpoint...

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Using Shell's IExtractImage to extract file thumbnail

    What about the pinvoke code on posting #4 ? I don't know how to call the function...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width