How to use IThumbnailProvider in Delphi 2010? [Edit]

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
0
Eric
7/28/2010 8:09:55 PM
embarcadero.delphi.nativeapi 1236 articles. 1 followers. Follow

5 Replies
3710 Views

Similar Articles

[PageSpeed] 25
Get it on Google Play
Get it on Apple App Store

<Eric Holzer> wrote in message news:266594@forums.embarcadero.com...

> 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.

Then there is likely no thumbnail preview available for the file to begin 
with.  What HRESULT value is BindToHandler() actually returning?

Where are you defining BHID_ThumbnailHandler, and with what GUID value?  My 
guess would be that you are trying to access a thumbnail provider that is 
not installed, or does not know how to render the file you are passing it 
it.

BTW, DO NOT call CoUninitialize() if CoInitializEx() fails.  That will get 
COM's internal reference count out of sync.

With that said, you should not be using IThumbnailProvider directly to begin 
with.  Use IShellItemImageFactory instead, as it delegates to 
IThumbnailProvider internally (and to IExractImage and IExtractIcon when 
IThumbnailProvider is not available), ie:

{code:delphi}
type
  {$EXTERNALSYM SIIGBF}
  SIIGBF = Integer;

  {$EXTERNALSYM IShellItemImageFactory}
  IShellItemImageFactory = interface(IUnknown)
    ['{BCC18B79-BA16-442F-80C4-8A59C30C463B}']
    function GetImage(size: TSize; flags: SIIGBF; out phbm: HBITMAP): 
HRESULT; stdcall;
  end;

const
  SIIGBF_RESIZETOFIT = $00000000;
  SIIGBF_BIGGERSIZEOK = $00000001;
  SIIGBF_MEMORYONLY = $00000002;
  SIIGBF_ICONONLY = $00000004;
  SIIGBF_THUMBNAILONLY = $00000008;
  SIIGBF_INCACHEONLY = $00000010;

function TForm1.GetThumb(AFilePath: string; var hBmp: HBITMAP): HRESULT;
var
  fileShellItemImage: IShellItemImageFactory;
  s: TSize;
begin
  Result := CoInitializeEx(nil, COINIT_APARTMENTTHREADED or 
COINIT_DISABLE_OLE1DDE);
  if Succeeded(Result) then begin
    Result := SHCreateItemFromParsingName(PChar(AFilePath), nil, 
IShellItemImageFactory, fileShellItemImage);
    if Succeeded(Result) then begin
      s.cx := 120;
      s.cy := 120;
      Result := fileShellItemImage.GetImage(s, SIIGBF_THUMBNAILONLY, hBmp);
    end;
    CoUninitialize;
  end;
end;
{code}

-- 
Remy Lebeau (TeamB)
0
Remy
7/28/2010 9:27:36 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> 
> Then there is likely no thumbnail preview available for the file to begin 
> with.  What HRESULT value is BindToHandler() actually returning?
> 
> Where are you defining BHID_ThumbnailHandler, and with what GUID value?  My 
> guess would be that you are trying to access a thumbnail provider that is 
> not installed, or does not know how to render the file you are passing it 
> it.
> 
> BTW, DO NOT call CoUninitialize() if CoInitializEx() fails.  That will get 
> COM's internal reference count out of sync.
> 
> With that said, you should not be using IThumbnailProvider directly to begin 
> with.  Use IShellItemImageFactory instead, as it delegates to 
> IThumbnailProvider internally (and to IExractImage and IExtractIcon when 
> IThumbnailProvider is not available), ie:
> 
> {code:delphi}
> type
>   {$EXTERNALSYM SIIGBF}
>   SIIGBF = Integer;
> 
>   {$EXTERNALSYM IShellItemImageFactory}
>   IShellItemImageFactory = interface(IUnknown)
>     ['{BCC18B79-BA16-442F-80C4-8A59C30C463B}']
>     function GetImage(size: TSize; flags: SIIGBF; out phbm: HBITMAP): 
> HRESULT; stdcall;
>   end;
> 
> const
>   SIIGBF_RESIZETOFIT = $00000000;
>   SIIGBF_BIGGERSIZEOK = $00000001;
>   SIIGBF_MEMORYONLY = $00000002;
>   SIIGBF_ICONONLY = $00000004;
>   SIIGBF_THUMBNAILONLY = $00000008;
>   SIIGBF_INCACHEONLY = $00000010;
> 
> function TForm1.GetThumb(AFilePath: string; var hBmp: HBITMAP): HRESULT;
> var
>   fileShellItemImage: IShellItemImageFactory;
>   s: TSize;
> begin
>   Result := CoInitializeEx(nil, COINIT_APARTMENTTHREADED or 
> COINIT_DISABLE_OLE1DDE);
>   if Succeeded(Result) then begin
>     Result := SHCreateItemFromParsingName(PChar(AFilePath), nil, 
> IShellItemImageFactory, fileShellItemImage);
>     if Succeeded(Result) then begin
>       s.cx := 120;
>       s.cy := 120;
>       Result := fileShellItemImage.GetImage(s, SIIGBF_THUMBNAILONLY, hBmp);
>     end;
>     CoUninitialize;
>   end;
> end;
> {code}
> 
> -- 
> Remy Lebeau (TeamB)

Remy, thanks for your hints.

The definition of BHID_ThumbnailHandler is in the shlobj.pas: 
BHID_ThumbnailHandler: TGUID  = '{7B2E650A-8E20-4F4A-B09E-6597AFC72FB0}';

I have tested my code with ico files and it does not work. 
Your code with the ImageFactory does not work for icons too.
For other files (jpg, bmp, gif) my and your code works fine.

Regards
Eric
0
Eric
7/28/2010 10:01:29 PM
<Eric Holzer> wrote in message news:266671@forums.embarcadero.com...

> I have tested my code with ico files and it does not work.
> Your code with the ImageFactory does not work for icons too.

Again, what actual HRESULT values are actually being returned?  If both 
codes are failing, then it is likely that you simply do not have any 
thumbnail provider installed for icon files.

BT, do you have the same problem if you use IThumbnailCache instead?

http://msdn.microsoft.com/en-us/library/ms631833.aspx

-- 
Remy Lebeau (TeamB)
0
Remy
7/28/2010 11:30:36 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> 
> Again, what actual HRESULT values are actually being returned?  If both 
> codes are failing, then it is likely that you simply do not have any 
> thumbnail provider installed for icon files.
> 
> BT, do you have the same problem if you use IThumbnailCache instead?
> 
> http://msdn.microsoft.com/en-us/library/ms631833.aspx
> 
> -- 
> Remy Lebeau (TeamB)

HResult for my code with IThumbnailProvider is -2147467263 ( 0x80004001) not implemented
HResult for your code with IShellItemImageFactory is -2147175936 (0x8004B200) ???
But your code works fine if I change the flag to 0 in the line "Result := fileShellItemImage.GetImage(s, 0, hBmp);" That is what I need. Thanks!!

I would like to test IThumbnailCache too, but I can not find all the definition guids. Please post the definition for IThumbnailCache if you have.

Eric
0
Eric
7/29/2010 7:56:51 PM
<Eric Holzer> wrote in message news:267148@forums.embarcadero.com...

> HResult for my code with IThumbnailProvider is
> -2147467263 ( 0x80004001) not implemented

There you go then.

> HResult for your code with IShellItemImageFactory
> is -2147175936 (0x8004B200) ???

That appears to be a custom error code from the thumbnail system.  No clue 
what it means.

> I would like to test IThumbnailCache too, but I can not find all
> the definition guids. Please post the definition for IThumbnailCache
> if you have.

Here you go.

{code:delphi}
const
  CLSID_LocalThumbnailCache: TGuid = 
'{50EF4544-AC9F-4A8E-B21B-8A26180DB13F}';
  CLSID_SharedBitmap: TGuid = '{4db26476-6787-4046-b836-e8412a9e8a27}';

type
  {$EXTERNALSYM WTS_FLAGS}
  WTS_FLAGS = (
    WTS_EXTRACT = 0,
    WTS_INCACHEONLY = 1,
    WTS_FASTEXTRACT = 2,
    WTS_FORCEEXTRACTION = 4,
    WTS_SLOWRECLAIM = 8,
    WTS_EXTRACTDONOTCACHE = 32,
    WTS_SCALETOREQUESTEDSIZE = 64,
    WTS_SKIPFASTEXTRACT = 128,
    WTS_EXTRACTINPROC = 256
  );

  {$EXTERNALSYM WTS_CACHEFLAGS}
  WTS_CACHEFLAGS = (
    WTS_DEFAULT = 0,
    WTS_LOWQUALITY = 1,
    WTS_CACHED = 2
  );
  PWTS_CACHEFLAGS = ^WTS_CACHEFLAGS;

  {$EXTERNALSYM WTS_ALPHATYPE}
  WTS_ALPHATYPE = (
    WTSAT_UNKNOWN = 0,
    WTSAT_RGB = 1,
    WTSAT_ARGB = 2
  );

  {$EXTERNALSYM WTS_THUMBNAILID}
  WTS_THUMBNAILID = record
    rgbKey: array[0..15] of Byte;
  end;
  PWTS_THUMBNAILID = ^WTS_THUMBNAILID;

  {$EXTERNALSYM ISharedBitmap}
  ISharedBitmap = interface(IUnknown)
    ['{091162a4-bc96-411f-aae8-c5122cd03363}']
    function GetSharedBitmap(out phbm: HBITMAP): HRESULT; stdcall;
    function GetSize(out pSize: TSize): HRESULT; stdcall;
    function GetFormat(out pat: WTS_ALPHATYPE): HRESULT; stdcall;
    function InitializeBitmap(hbm: HBITMAP; wtsAT: WTS_ALPHATYPE): HRESULT; 
stdcall;
    function Detach(out phbm: HBITMAP): HRESULT; stdcall;
  end;

  {$EXTERNALSYM IThumbnailCache}
  IThumbnailCache = interface(IUnknown)
    ['{F676C15D-596A-4ce2-8234-33996F445DB1}']
    function GetThumbnail(pShellItem: IShellItem; cxyRequestedThumbSize: 
UINT; flags: WTS_FLAGS; out ppvThumb: ISharedBitmap; pOutFlags: 
PWTS_CACHEFLAGS; pThumbnailID: PWTS_THUMBNAILID): HRESULT; stdcall;
    function GetThumbnailByID(thumbnailID: WTS_THUMBNAILID; 
cxyRequestedThumbSize: UINT; out ppvThumb: ISharedBitmap; pOutFlags: 
PWTS_CACHEFLAGS): HRESULT; stdcall;
  end;
{code}

-- 
Remy Lebeau (TeamB)
0
Remy
7/29/2010 8:40:32 PM
Reply:

Similar Artilces:

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

Problem using InstallAware 7 CodeGear Special Edition with Delphi 2010 [Edit]
Hi Everyone, I am trying to create an installation disk for my delphi 2010 application using the installAware that kind of comes with Delphi 2010. When I try to built it, it keeps giving me the error message:- No files matching pattern "C:\Windows\system32\\*120.bpl" and when I look into my windows\system32 folder, there the files with extension *.bpl end with *140.bpl and not *120.bpl like it was expected. Can anyone tell me if I am doing something wrong or how I can get around this. Thanks in advance. Edited by: Tat Hon Chu on Dec 3, 2009 12:55 AM > {quo...

Code works in Delphi 7 but not in Delphi 2010 [Edit]
hello, i have a procedure that open's a file by passing the file name as the parameter to the executable. something like this {code} C : \ P r o g r a m F i l e s \ Da c k e r \ D r a c k e r . e x e " G : \ D E l p h i 7 \ D e l p h i 7 A p p _ l o g . t " {code} The source code is {code} procedure OpenFileWithExe var hReg: HKEY; Ret: Longint; RegDataType, RegDataSize: DWORD; CmdLine: array [0..560] of Char; Len: Integer; SInfo: TStartupInfo; PInfo: TProcessInformation; begin Ret := windows.RegOpenKeyEx(HKEY_CURRENT_USER, ...

Update Delphi 2005 to Delphi 2010, which do i need? [Edit]
Hello, we have one Delphi 2005 Professional here and want to upgrade to Delphi 2010, but we are a bit confused. Our distributor in Germany, ingram-micro offers several upgrade products: UPG DELPHI 2010 PRO - NAMED USER UPG DELPHI 2010 PRO - NAMED USER ELS UPG DELPHI 2010 PRO - NAMED USER FLEX RAD STUDIO 2010 PRO - UPG UPG RAD STUDIO 2010 PRO - NAMED ELC UPG RAD STUDIO 2010 PRO - NAMED FLEX UPG DELPHI 2010 PRO - CONCURRENT ELS UPG DELPHI 2010 PRO - CONCURRENT FLEX What do they mean exactly and which one do i need? At the moment delphi is installed on two PCs and we want to use ...

Using WordApplication in Delphi 2010 [Edit]
Hello Everyone, I am having a problem with WordApplicatio component. I am using Delphi 10. I can get the WordApplication to open with the Document template that I select, but Word is behind my app and when I close Word I get an RPC Server not available errror and after that a pointer violation and then access violations until I reset the IDE. Here is the code I am using: procedure TTestLetterForm.Button1Click(Sender: TObject); var FileName: oleVariant; begin //Letter2Report.Print; if OpenDialog.Execute = True then begin FileName := OpenDialog.Fil...

Delphi 2010 produces much larger binaries than Delphi 2009 [Edit]
When I compile my project with Delphi 2010 the resulting executable is about 30% larger than the one compiled with Delphi 2009. Both binaries are compiled with the same source code and project options. The size of individual DCU files increases by 5-20%. Has anybody experienced similar results? Has anybody an idea what could cause this? It surprises me, as the changes in syntax and VCL have not been that big. Best regards, Joachim Edited by: Joachim Marder on Sep 25, 2009 6:07 AM "Joachim Marder" wrote in message news:166152@forums.codegear.com... > When I compi...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

from delphi 6 to delphi 2010
Hi. It is possible, with component RX, dxforumlibrary, InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. Thank by comments. excequiel arostica wrote: >Hi. > It is possible, with component RX, dxforumlibrary, >InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. > >Thank by comments. Rx is dead and sources are taken over by jcl/jvcl. I dont know about the rest of the components and i have no experiences with bde over the last 9 years. excequiel arostica wrote: > Hi. > It is possible, with component RX, dxforumlibrary,...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Using TTrayIcon Component in BDS 2006 in Delphi 2010 [Edit]
This message is no longer available. ...

Price of upgrade from Delphi 2010 Professional to Delphi 2010 Enterprise?
It's weird, but I could not find the answer on so simple question not in Embarcadero Shop, neither by the forum search. For example, the shop info about Enterprise upgrade says: The Upgrade product is available to registered owners of 2006-2009 versions, blah-blah... So, if I'm Delphi 2010 Professional user, I even not eligible for upgrade? I have to buy a new version of Enterprise??? But if I'm Delphi 2006 Professional user, I can upgrade. Please clarify this nonsense for me. Exact question is in the subject. Thanks! Hi Dmitri, > It's weird, but I could not...

delphi 2006 code in delphi 2010
hello, is there any option to make delphi 2006 code work in delphi 2010? something like in java IDEs where you can define the code level you like to use? the problem is, that i made a project with 2006 and sent it to my customer. they got 2010 and it compiles fine, but it just doesn't work. it deals with en-/decryption of text, we assumed, that it has something to do with ansi vs. unicode strings... but we cant find the exact position where the error occurs. i am a bit dissapointed, because everywhere i read that the new IDE will always be downwards compatible and so on.. but in ...

Delphi 2010 w Delphi 2007
I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). Can I install D2010 on this machine without it affecting D2007? Will D2010 affect D2007 in any way? Thanks, Randall Carpenter > {quote:title=Randall Carpenter wrote:}{quote} > I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). > Can I install D2010 on this machine without it affecting D2007? Will D2010 > affect D2007 in any way? Won't hurt a thing. I have D7, RAD Studio 2007, RAD Studio 2009, and RAD Studio 2010 all on my desktop system and they coexist fine. Jus...

Migrate from Delphi 2007 to Delphi 2010
Hi All, Thanks in advance for your help. Below is my query, Currently I am using Delphi 2007 and i want to migrate to Delphi 2010. 1. What all things i need to take care while doing this? 2. What all third party components will get impacted? 3. Any known issues in Delphi 2010 which might impact the cause? 4. Any changes in database operation required as i am using Oracle? Hope I have post this query under correct category. If not sorry for the trouble and could you please suggest me the correct category for this? Looking forward for your response. Have a great day. Th...

Web resources about - How to use IThumbnailProvider in Delphi 2010? [Edit] - embarcadero.delphi.nativeapi

Features new to Windows Vista - Wikipedia, the free encyclopedia
Windows Vista (formerly codenamed Longhorn ) has many new features compared with previous Microsoft Windows versions, covering most aspects of ...

Tutorials • benryves.com
Journal Gallery Products Projects Tutorials Tutorials Some of the tutorials here are quite old, so do not hesitate to contact me if you have ...

Resources last updated: 12/7/2015 11:39:22 PM