How to use IThumbnailProvider in Delphi 2010? [Edit]

Giganews Newsgroups
Subject: How to use IThumbnailProvider in Delphi 2010? [Edit]
Posted by:  Eric Holzer
Date: Wed, 28 Jul 2010

Hello,

I try to use IThumbnailProvider for getting thumbnail from the file.
I can not get ThumbnailProvider, the result of the line "result := fileShellItem.BindToHandler(nil, BHID_ThumbnailHandler, IID_IThumbnailProvider, thumbProvider );" is always false.
Could someone help me?

Regards
Eric

P.S.
I use Win7/64

type
{$EXTERNALSYM IThumbnailProvider}
  IThumbnailProvider = interface(IUnknown)
    ['{e357fccd-a995-4576-b01f-234630154e96}']
    function GetThumbnail(cx : uint; out hBitmap : HBITMAP; out bitmapType : dword):HRESULT;stdcall;
  end;

const
{$EXTERNALSYM IID_IThumbnailProvider}
  IID_IThumbnailProvider: TGUID = '{e357fccd-a995-4576-b01f-234630154e96}';

Implementation

function TForm1.GetThumb(AFilePath: string; var hBmp: HBITMAP):HRESULT;
var fileShellItem: IShellItem;
    thumbProvider: IThumbnailProvider;
    bmpType: dword;
begin
    Result := CoInitializeEx(nil, COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE);
    if Succeeded(Result) then begin
      Result := SHCreateItemFromParsingName(PWideChar(AFilePath), nil, IID_IShellItem, fileShellItem);
      if Succeeded(Result) then begin
          result := fileShellItem.BindToHandler(nil, BHID_ThumbnailHandler, IID_IThumbnailProvider, thumbProvider );
          if Succeeded(Result) then begin
            Result := thumbProvider.GetThumbnail(120, hBmp, bmpType);
          end;
          thumbProvider := nil;
      end;
      fileShellItem := nil;

    end;
  CoUninitialize;
end;

Edited by: Eric Holzer on Jul 28, 2010 1:08 PM

Replies