thumbnail extraction win32com -how?

Guy Robinson guy at NOSPAM.r-e-d.co.nz
Mon Sep 13 08:15:43 EDT 2004


Hello,

I revist this every now and then and are still no closer to getting it to work. 
I want to extract the thumbnail from a file on windows using either win32com or 
ctypes. As described in this link:

http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/article.asp

Has anyone implemented this? Or can explain how to do this. Basically it 
involves calling IExtractImage from shell32. But I'm not sure how to get the 
file object or access IExtractImage.

This is what I have so far (which doesn't work):

import win32com.client
Dispatch = win32com.client.Dispatch

objShell = Dispatch("Shell.Application");
objFolder = objShell.Namespace(0);
localPidl = objFolder.ParseName('path\filename');
uio = objShell.GetUIObjectOf(NULL, 1, localPidl,IID_IExtractImage,NULL,IExtract)
...

Based on the following C code:

"""
HBITMAP ExtractThumb(LPSHELLFOLDER psfFolder, LPCITEMIDLIST localPidl,
                      const SIZE* prgSize, DWORD dwRecClrDepth)
{
    LPEXTRACTIMAGE pIExtract = NULL;
    HRESULT hr;
    hr = psfFolder->GetUIObjectOf(NULL, 1, &localPidl, IID_IExtractImage,
                                  NULL, (void**)&pIExtract);
    if(NULL == pIExtract) // early shell version, thumbs not supported
       return NULL;

    OLECHAR wszPathBuffer[MAX_PATH];
    DWORD dwPriority = 0; // IEI_PRIORITY_NORMAL is defined nowhere!
    DWORD dwFlags = IEIFLAG_SCREEN;
    HBITMAP hBmpImage = NULL;
    hr = pIExtract->GetLocation(wszPathBuffer, MAX_PATH, &dwPriority,
                                prgSize, dwRecClrDepth, &dwFlags);
    // even if we've got shell v4.70+, not all files support thumbnails
    if(NOERROR == hr) hr = pIExtract->Extract(&hBmpImage);
    pIExtract->Release();

    return hBmpImage; // callers should DeleteObject this handle after use
}
"""

regards,

Guy



More information about the Python-list mailing list