The MASM Forum

General => The Campus => Topic started by: xandaz on May 30, 2012, 08:53:46 AM

Title: Geting Icon index or handle from file extention!
Post by: xandaz on May 30, 2012, 08:53:46 AM
    i'm making a rar extractor and while the content of the file is still compacted i need to extract either the index or handle of the icon that corresponds to the extention. I'm not aware of any function that could do so. I tried ExtracAssociatedIconEx and ExtractIcon with 0 for module Instance but didn't work. Can it be done via registry. Does anybody have any idea? Thanks in advance.
    Laters
    X
Title: Re: Geting Icon index or handle from file extention!
Post by: Gunner on May 30, 2012, 09:17:16 AM
Stay OUT of the Registry.  Use SHGetFileInfo

Something like this should work:
    invoke  SHGetFileInfo, offset szExtension, NULL, offset sfi, sizeof SHFILEINFO, SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON
    invoke  ImageList_AddIcon, himlTabs, sfi.hIcon
    invoke  DestroyIcon, sfi.hIcon

this will fill in the icon index in the system imagelist sfi.iIcon and the handle of the icon sfi.hIcon
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 30, 2012, 09:20:02 AM
   yea? but does it work with just the extention? what's the format?
*.rar

...cause i tried that and didnt work.
   thanks gunner i appreciate the help. I'm waittin.
   soon
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 30, 2012, 09:23:32 AM
  oh yeah gunner. after reading the sdk i understood. thanks gunna.
  later and regards
  x
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 30, 2012, 11:19:03 PM
   Couldn't get it to work... does anyone know what's the extention fomat? Is it '*.ext',0 or what?
Title: Re: Geting Icon index or handle from file extention!
Post by: dedndave on May 31, 2012, 12:01:29 AM
try passing a "fictional" filename. like 'x.rar',0

also - set the SHFILEINFO dwAttributes member to FILE_ATTRIBUTE_NORMAL before the call
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 31, 2012, 12:14:49 AM
    thanks dave. will do so... i'll let you know how it went.
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 31, 2012, 12:29:56 AM
   Not working.... even tried FILE_ATTR_COMPRESSED and both and none.
Title: Re: Geting Icon index or handle from file extention!
Post by: dedndave on May 31, 2012, 12:31:55 AM
alright - let me play with it...
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 31, 2012, 12:41:50 AM
   wait....it works.... it was an listview problem.... forgot to xor imask,LVIF_IMAGE+PARAM that's all. Sorry.... i always miss something stupid. Thanks dave and gunner
Title: Re: Geting Icon index or handle from file extention!
Post by: dedndave on May 31, 2012, 12:45:09 AM
yah - my mistake, too
you set the file attribute in the parm - not in the struct...
        INVOKE  SHGetFileInfo,offset szExtension,FILE_ATTRIBUTE_NORMAL,offset shfi,sizeof SHFILEINFO,
                SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON


also - it appears that '.rar',0 will work for an extension format
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 31, 2012, 12:53:07 AM
    oks.... althought i read here...http://blogs.msdn.com/b/oldnewthing/archive/2004/06/01/145428.aspx (http://blogs.msdn.com/b/oldnewthing/archive/2004/06/01/145428.aspx)
    thx dave. i appreciate it.... i'm coming close to about 2000 lines of code devided be several source files. I feel tired. I'll prolly drop once i get bored as i do with everything else....lol. bb
Title: Re: Geting Icon index or handle from file extention!
Post by: dedndave on May 31, 2012, 02:08:00 AM
yah - i saw that article
but - you may also want to read the community content at the bottom...
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179%28v=vs.85%29.aspx)
Title: Re: Geting Icon index or handle from file extention!
Post by: xandaz on May 31, 2012, 02:27:04 AM
   thx. dave. will do.