question

Sebastian-5089 avatar image
0 Votes"
Sebastian-5089 asked Sebastian-5089 commented

IShellItem::BindToHandler fails for too many file types

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
thumbnail.png (6.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
1 Vote"
Castorix31 answered Sebastian-5089 commented

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);
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot for sharing! It's interesting, because this fails here on two Windows machines because pShellItemImageFactory is null.

0 Votes 0 ·

What does hr return for SHCreateItemFromIDList ?
(I tested on Windows 10 1909)

0 Votes 0 ·

I was to focused on the callback. The function failed to initialize CoInitializeEx, it works now! Thanks so much!

0 Votes 0 ·
XiaopoYang-MSFT avatar image
0 Votes"
XiaopoYang-MSFT answered

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



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sebastian-5089 avatar image
0 Votes"
Sebastian-5089 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.