# Visual Basic > Visual Basic 6 and Earlier >  Help with NameSpace ExtendedProperty thumbnail

## k_zeon

I use the following code below to get an Image from a video file but wanted to know if there is a similar way to get a thumbnail image
for a photo.
I use GDI at present to get an image from photo and place on a flexigrid, but wanted to know if there is a namespace option that would process
the file quicker. or any other method thats faster.

tks




```
Public Function GetVideoThumbnail(ByVal Filename As String) As StdPicture
    Dim ThumbnailStream As IUnknown
    Dim GdipTool As New GdipTool

    With shell32.NameSpace(ssfDesktop).ParseName(Filename)
        Set ThumbnailStream = .ExtendedProperty("System.ThumbnailStream")
        If Not ThumbnailStream Is Nothing Then
            Set GetVideoThumbnail = GdipTool.Stream2PicScaled(ThumbnailStream, 300, 300)
        End If

    End With
End Function
```

----------


## -Franky-

Hi
I use the IShellItemImageFactory interface to create thumbnails of files. SHCreateItemFromParsingName -> IShellItemImageFactory -> IShellItemImageFactory.GetImage -> hBitmap. I have no idea if that's faster.

----------


## k_zeon

> Hi
> I use the IShellItemImageFactory interface to create thumbnails of files. SHCreateItemFromParsingName -> IShellItemImageFactory -> IShellItemImageFactory.GetImage -> hBitmap. I have no idea if that's faster.


do you have any sample code you could share. tks.
would like to test

----------


## fafalone

I've never tested speeds to compare but there's numerous other ways of getting thumbnails. The absolute quickest method would be if it's already cached by the system, you can access the cache. That method also includes an option to create it if not already cached. So if most of the images you want thumbnails for are already cached, or you'll be accessing them repeatedly, that will likely be the quickest method.

You also have IShellItemImageFactory, IExtractImage, IShellImageData, directly loading it with GDIP, and a few others.

----------


## fafalone

Since you asked about IShellItemImageFactory:



```
Dim isiif As IShellItemImageFactory
Dim hr As Long

Dim hBmp As Long
hr = SHCreateItemFromFromParsingName(StrPtr(path), Nothing, IID_IShellItemImageFactory, isiif)
hr = isiif.GetImage(width, height, flags, hBmp)

'do whatever you want with the HBITMAP image
End Function
```

In a project with oleexp.tlb/mIID.bas.

----------


## -Franky-

Hi
or without oleexp.tlb/mIID.bas


```
Option Explicit


' ----==== Const ====----
Private Const S_OK As Long = &H0&
Private Const API_TRUE As Long = &H1&
Private Const CC_STDCALL As Long = &H4&
Private Const IID_IPicture As String = "{7bf80980-bf32-101a-8bbb-00aa00300cab}"
Private Const IID_IShellItemImageFactory As String = "{bcc18b79-ba16-442f-80c4-8a59c30c463b}"


' ----==== Enums ====----
Private Enum vtb_Interfaces
    
    ' IUnknown
    IUnknown_Release = 2


    ' IShellItemImageFactory
    IShellItemImageFactory_GetImage = 3
    
End Enum


Public Enum SIIGBF
    SIIGBF_RESIZETOFIT = &H0
    SIIGBF_BIGGERSIZEOK = &H1
    SIIGBF_MEMORYONLY = &H2
    SIIGBF_ICONONLY = &H4
    SIIGBF_THUMBNAILONLY = &H8
    SIIGBF_INCACHEONLY = &H10
    SIIGBF_CROPTOSQUARE = &H20
    SIIGBF_WIDETHUMBNAILS = &H40
    SIIGBF_ICONBACKGROUND = &H80
    SIIGBF_SCALEUP = &H100
End Enum


' ----==== Types ====----
Private Type GUID
    data1 As Long
    data2 As Long
    data3 As Long
    data4 As Long
End Type


Private Type PICTDESC
    cbSizeOfStruct As Long
    PicType As Long
    hgdiObj As Long
    hPalOrXYExt As Long
End Type


' ----==== Ole32.dll Declarations ====----
Private Declare Function CLSIDFromString Lib "Ole32.dll" ( _
                         ByVal pstring As Long, _
                         ByRef pCLSID As GUID) As Long
                         
' ----==== Oleaut32.dll Declarations ====----
Private Declare Function DispCallFunc Lib "Oleaut32.dll" ( _
                         ByVal pvInstance As Long, _
                         ByVal oVft As Long, _
                         ByVal cc As Long, _
                         ByVal vtReturn As VbVarType, _
                         ByVal cActuals As Long, _
                         ByVal prgvt As Any, _
                         ByVal prgpvarg As Any, _
                         ByRef pvargResult As Variant) As Long


Private Declare Function OleCreatePictureIndirect Lib "Oleaut32.dll" ( _
                         ByRef lpPictDesc As PICTDESC, _
                         ByRef rIID As GUID, _
                         ByVal fOwn As Long, _
                         ByRef lplpvObj As Object) As Long


' ----==== Shell32.dll Declarations ====----
Private Declare Function SHCreateItemFromParsingName Lib "Shell32.dll" ( _
                         ByVal pszPath As Long, _
                         ByVal pBC As Long, _
                         ByRef rIID As GUID, _
                         ByRef pUnk As Long) As Long


Public Function GetThumbnail(ByVal ShellItem As String, _
                             ByVal ThumbSize As Long, _
                             Optional ByVal Flags As SIIGBF = SIIGBF_RESIZETOFIT) As StdPicture
    Dim Ret As StdPicture
    If Len(ShellItem) <> 0 Then
        Dim pIShellItemImageFactory As Long
        If SHCreateItemFromParsingName(StrPtr(ShellItem), 0&, _
                                       Str2Guid(IID_IShellItemImageFactory), _
                                       pIShellItemImageFactory) = S_OK Then
            Dim hBitmap As Long
            If Invoke(pIShellItemImageFactory, IShellItemImageFactory_GetImage, _
                      ThumbSize, ThumbSize, Flags, VarPtr(hBitmap)) = S_OK Then
                If hBitmap <> 0& Then
                    Dim tPictDesc As PICTDESC
                    With tPictDesc
                        .cbSizeOfStruct = LenB(tPictDesc)
                        .PicType = vbPicTypeBitmap
                        .hgdiObj = hBitmap
                    End With
                    Dim oPicture As Object
                    If OleCreatePictureIndirect(tPictDesc, Str2Guid(IID_IPicture), _
                                                API_TRUE, oPicture) = S_OK Then
                        Set Ret = oPicture
                        Set oPicture = Nothing
                    End If
                End If
            End If
            Call Release(pIShellItemImageFactory)
        End If
    End If
    Set GetThumbnail = Ret
End Function


Private Sub Release(ByRef pInterface As Long)
    Dim lngRet As Long
    If pInterface <> 0& Then
        Call Invoke(pInterface, IUnknown_Release)
        pInterface = 0&
    End If
End Sub


Private Function Invoke(ByVal pInterface As Long, _
                        ByVal vtb As vtb_Interfaces, _
                        ParamArray var()) As Variant
    If pInterface <> 0& Then
        Invoke = OleInvoke(pInterface, vtb, var)
    End If
End Function


Private Function OleInvoke(ByVal pInterface As Long, _
                           ByVal lngCmd As Long, _
                           ParamArray aParam()) As Variant
    If pInterface <> 0& Then
        If UBound(aParam) >= 0& Then
            Dim varParam As Variant
            varParam = aParam
            If IsArray(varParam) Then varParam = varParam(0)
            Dim lngCount As Long
            lngCount = UBound(varParam)
            Dim lngItem As Long
            Dim olePtr(10) As Long
            Dim oleTyp(10) As Integer
            For lngItem = 0& To lngCount
                oleTyp(lngItem) = VarType(varParam(lngItem))
                olePtr(lngItem) = VarPtr(varParam(lngItem))
            Next
        End If
        Dim varRet As Variant
        If DispCallFunc(pInterface, lngCmd * 4, CC_STDCALL, _
                        vbLong, lngItem, VarPtr(oleTyp(0)), _
                        VarPtr(olePtr(0)), varRet) <> S_OK Then
        End If
    End If
    OleInvoke = varRet
End Function


Private Function Str2Guid(ByVal strGUID As String) As GUID
    Call CLSIDFromString(StrPtr(strGUID), Str2Guid)
End Function
```

and call GetThumbnail


```
Picture1.Picture = GetThumbnail("D:\Downloads\VBC_Prog\VBC_MediaFoundation\test.mp4", 300)
```

----------


## k_zeon

> Hi
> or without oleexp.tlb/mIID.bas
> 
> 
> ```
> Option Explicit
> 
> 
> ' ----==== Const ====----
> ...


tks. as you examples shows mp4 file, would this also work with jpg files. tks

edit: just tested and it does. will test speed differences. tks

----------


## -Franky-

It works with all ShellItems. e.g. files, folders, drives, etc.  :Smilie:

----------

