IShellItem::BindToHandler fails for too many file types

Sebastian 41 Reputation points
2021-06-21T04:06:14.49+00:00

Hello,

I'm trying to extract a thumbnail from the given file below.

107451-thumbnail.png

For this I use SHCreateItemFromParsingName and IShellItem::BindToHandler. For several file types this works fine, but for various other file types BindToHandler only returns E_NOTIMPL Not implemented. and I am not sure why.

Normally thumbnails can be registered through thumbnail providers. Is there another method I am not aware of? This would explain why the example above fails. I stripped down the code to the absolut minimum:

   #include <windows.h>  
   #include <shlobj.h>  
   #include <thumbcache.h>  
   #include <iostream>  
   #include <shellapi.h>  
     
   #pragma comment(lib, "SHELL32.LIB")  
   #pragma comment(lib, "Comctl32.lib")  
     
   int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {  
   HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);  
     if (!SUCCEEDED(hr))  
     {  
       return -1;  
     }  
     
   IShellItem* psi = nullptr;  
     hr = SHCreateItemFromParsingName(argv[1], NULL, IID_PPV_ARGS(&psi));  
     if (SUCCEEDED(hr)) {  
       IThumbnailProvider* pThumbProvider;  
       hr = psi->BindToHandler(NULL, BHID_ThumbnailHandler, IID_PPV_ARGS(&pThumbProvider));  
       if (SUCCEEDED(hr)) {  
         std::wcout << L"this line never succeeds";  
       }  
     }  
     return 0;  
   }  

Could anyone help out and explain what might go wrong here?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 83,206 Reputation points
    2021-06-21T15:32:45+00:00

    This test works for me with a .clip file =>

        PIDLIST_ABSOLUTE pidl;  
        HRESULT hr = SHParseDisplayName(L"C:\\Users\\Christian\\Documents\\illustration.clip", NULL, &pidl, 0, NULL);
        IShellItemImageFactory* pShellItemImageFactory;
        hr = SHCreateItemFromIDList(pidl, IID_PPV_ARGS(&pShellItemImageFactory));
        HBITMAP hBitmap;
        SIZE size;
        size.cx = 320;
        size.cy = 200;
        hr = pShellItemImageFactory->GetImage(size, SIIGBF_RESIZETOFIT | SIIGBF_THUMBNAILONLY, &hBitmap);
        // Test display on screen
        HDC hDC = GetDC(NULL);
        HDC hDCMem = CreateCompatibleDC(hDC);
        HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDCMem, hBitmap);
        BitBlt(hDC, 0, 0, size.cx, size.cy, hDCMem, 0, 0, SRCCOPY);
        SelectObject(hDCMem, hBitmapOld);
        DeleteObject(hDCMem);
        ReleaseDC(NULL, hDC);
    
    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,231 Reputation points Microsoft Vendor
    2021-06-21T09:19:41.54+00:00

    You can refer to this Extract thumbnail for any file in Windows question which provides a solution that extracts a thumbnail.

    0 comments No comments

  2. Sebastian 41 Reputation points
    2021-06-21T14:17:23.377+00:00

    Thanks for sharing! I will try this, but isn't there a C++ solution for this?

    0 comments No comments