Goal is to get files thumbnails from selected folder on windows in a minimum possible amount of time.
Imagemagick and other tools open files every time, so they may not be the most efficient. Built-in mechanism in Windows has a possibility that the thumbnails can be in cache, which theoretically gives a considerable speed boost.
From How to get thumbnail of file using the Windows API? (answer) it became clear about the ways, but there was a lot of problems:
- IThumbnailProvider and IThumbnailCache not found in:
- ctypes.windll.shell32 (there is only functions, and seems that there is no simple way to get interfaces)
- win32com.shell.shell (PyWin32)
- IID_IThumbnailProvider and IShellItemImageFactory through SHCreateItemFromParsingName and IID:
That IID's not found in win32com.shell.shell, so they was provided manually.
IThumbnailProvider, IShellItem::BindToHandler method: fixed, but now error is the same as below:
# str(shell.IID_IShellItem) == '{43826D1E-E718-42EE-BC55-A1E261C37BFE}' # str(shell.BHID_ThumbnailHandler) == '{7B2E650A-8E20-4F4A-B09E-6597AFC72FB0}' item = shell.SHCreateItemFromParsingName(r'd:\some.png', None, str(shell.IID_IShellItem)) # str() is works IID_IThumbnailProvider = '{e357fccd-a995-4576-b01f-234630154e96}' provider = item.BindToHandler(None, shell.BHID_ThumbnailHandler, IID_IThumbnailProvider) # error > TypeError: 'There is no interface object registered that supports this IID'
IShellItemImageFactory: suspect that there is wrong usage of IID, but from answer below it should work:
IID_IShellItemImageFactory = '{bcc18b79-ba16-442f-80c4-8a59c30c463b}' item = shell.SHCreateItemFromParsingName(r'd:\some.png', None, IID_IShellItemImageFactory) # error > TypeError: 'There is no interface object registered that supports this IID'
It would be great to understand how to swim in all this without learning the whole winapi..
Thanks in advance.
Windows 10 (20H2), Python 3.9.5, PyWin32 301
Update: Found answer about PyWin32 (pythoncom.CoCreateInstance can't create IZoneIdentifier; the interface is missing from registry too despite being documented in MSDN). In short, these interfaces are not implemented. Checked by:
> import pythoncom
> pythoncom.InterfaceNames
So .. there are 2 questions left. Are there any options to get to thumbnails without using PyWin32? Via ctypes, for example. And how?