The problem is that TIcon currently cannot cope with handles (TIcon.setHandles is not yet implemented => TIcon.LoadFromBitmapHandles fails).
You can work around with a TBitmap:
uses
... Graphics, Windows, ShellApi, ...
function TForm1.GetFileInfosFromExt(const AExt: string; const GetSmallIcon : boolean; var anIcon : TIcon; out aDescr, aTypeName : string): boolean;
var
SFI: SHFileInfo;
flags : dword;
myIconInfo: TIconInfo;
winBitmap: windows.TBitmap;
aBmp : graphics.TBitmap;
begin
result:=false;
if GetSmallIcon then
flags:=SHGFI_SMALLICON
else
flags:=SHGFI_LARGEICON;
flags:=flags or SHGFI_ICON or SHGFI_USEFILEATTRIBUTES or SHGFI_DISPLAYNAME or SHGFI_TYPENAME;
if SHGetFileInfo(PChar(AExt), $80, SFI, SizeOf(SHFileInfo), flags)<>0 then // Windows FILE_ATTRIBUTE_NORMAL=$80
begin
if (assigned(anIcon)) and (sfi.hIcon <> 0) and (GetIconInfo(sfi.hIcon, myIconInfo)) then
begin
aBmp := graphics.TBitmap.Create;
aBmp.LoadFromBitmapHandles(myIconInfo.hbmColor, myIconInfo.hbmMask, nil); // @r
anIcon.Assign(aBMP); // there is no other way for TIcons - you MUST use a Bitmap, as it has implemented "Handles"-handling (setHandles)
// TIcons themselves cannot cope with handles
aBmp.Free;
end;
aDescr := sfi.szDisplayName;
aTypeName := sfi.szTypeName;
result:=true;
end;
end;