News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SHGetFileInfo help

Started by maruf10, February 23, 2010, 06:46:00 PM

Previous topic - Next topic

maruf10

Hello all ...
I want to use SHGetFileInfo function  in masm32 to check icon type of an .exe file whether it is a folder icon or not .
would you please explain its parameter and how to use it ?? especially how to check folder icon ??
if it returns true for folder icon i want to delete it .
Thanks in advance ...

BlackVortex

Interesting, I made a little console app to return info. I'm too tired now to make it presentable. Main stuff is :

target               db "testfolder",0   ;name of the object we're interested in, can be full path, otherwise in same dir
shfi                 SHFILEINFO <>   ;we will get our info in this structure
invoke SHGetFileInfo, addr targetname, NULL, addr shfi, sizeof shfi, SHGFI_ICON+SHGFI_LARGEICON+SHGFI_ICONLOCATION+SHGFI_TYPENAME


Then the structure gets filled and you get back :

shfi.szDisplayName string with path to the file containing the icon, example :  "C:\Windows\system32\imageres.dll"
shfi.szTypeName, string wiith a name of the type of the object, for a folder it is : "File folder"
shfi.iIcon, integer which is the icon index in the file, example, default folder icon is index 1 in imageres.dll
shfi.hIcon, handle to the icon

If you get stuck, I will post a fully working tool tomorrow.

maruf10

"File Folder" is not working   :eek
what is the problem ??


.if shfi.szTypeName == "File folder"
;some code to delete that file
.endif

dedndave

imageres.dll is not a folder ?

BlackVortex

You should use shfi.szTypeName

If you want to delete all folders without a non-default icon, you should also check the icon index.

maruf10

this is the code portion

.code
start:

.data
TestFolder db "H:\game" , 0
shfi SHFILEINFO <>
FileFolder db "This is a folder icon" , 0
NotFolder db "This is not a folder icon" , 0

.code
invoke SHGetFileInfo , addr TestFolder , NULL , addr shfi , sizeof shfi ,  SHGFI_ICON + SHGFI_LARGEICON + SHGFI_ICONLOCATION + SHGFI_TYPENAME




.if shfi.szTypeName == "File Folder"
invoke StdOut , addr FileFolder
                .else
invoke StdOut , addr NotFolder
                .endif
     


       invoke ExitProcess , 0
END start


this line the generating error

Quote
.if shfi.szTypeName == "File Folder"

error:

Quote
error A2084: constant value too large

where is the problem !!! :dazzled:

qWord

you can not compare strings using .if/.elseif - use this:
include masm32rt.inc
...
.if rv(szCmp,OFFSET shfi.szTypeName,"File Folder")

or

.if rv(szCmpI,OFFSET shfi.szTypeName,"File Folder")


for more than one string compare you can use the switch$-macro:
switch$ OFFSET shfi.szTypeName
case$ "File Folder"
;...
case$ "WhatEver"
;...
else$
;...
endsw$

FPU in a trice: SmplMath
It's that simple!

maruf10

Cooool ....
There is another problem ...

i hv placed three .exe file named firefox.exe , updater.exe , ashQuick.exe in a folder and using this code portion :


invoke SHGetFileInfo , addr aline , NULL , addr shfi , sizeof shfi , SHGFI_ICON + SHGFI_LARGEICON +           
                        SHGFI_ICONLOCATION + SHGFI_TYPENAME+SHGFI_USEFILEATTRIBUTES
                 
                        invoke StdOut , OFFSET shfi.szTypeName
                      invoke StdOut , OFFSET shfi.iIcon



but there is no difference in output ...

Quote

Application♥
Application♥
Application♥


but all those files icons are different ...  :eek
i think output should be different for each different file
what can i do now ?!?!

BlackVortex

How many times do I have to say that Typename is the type ? They are all applications !  :naughty:

What's different is the icon index, which you don't print correctly, because that one isn't a string, it's a number, you have to convert it in order to type it. (That's why you're getting those hearts at the output probably, it's not homo from your PC)

BlackVortex

Well, this a little test I made, there is a lot of info you can get with that API, maybe later I can show more things, I'm kinda multitasking right now.

This is GoAsm code, but it's very close to MASM you should have no problem, compile as console app. And you can only select files with this, not folders. And ignore, where it says "error" lol

qWord

Quote from: maruf10 on February 25, 2010, 02:49:40 PM
... SHGFI_ICON ...
Do not forget to close the icons handle using  DestroyIcon().

BTW: it is not a good practise to use '+' for linking flags - use 'or'.
FPU in a trice: SmplMath
It's that simple!

Slugsnack

Quote from: qWord on February 24, 2010, 06:45:17 PM
you can not compare strings using .if/.elseif - use this:
include masm32rt.inc
...
.if rv(szCmp,OFFSET shfi.szTypeName,"File Folder")

or

.if rv(szCmpI,OFFSET shfi.szTypeName,"File Folder")


for more than one string compare you can use the switch$-macro:
switch$ OFFSET shfi.szTypeName
case$ "File Folder"
;...
case$ "WhatEver"
;...
else$
;...
endsw$


Hehe can be done with strings of 4 characters or less :]

qWord

Quote from: Slugsnack on February 25, 2010, 09:11:16 PM
Hehe can be done with strings of 4 characters or less :]
theoretical any size  :bg
mov edi,chr$("Some Size")
assume edi: ptr DWORD
.if [edi] == "emoS" && [edi+4] == "ziS " && WORD ptr [edi+8] == "e"
invoke MessageBox,0,0,0,0
.endif
FPU in a trice: SmplMath
It's that simple!

maruf10

many many thanks to all...
I have checked BlackVortex's code ....
It outputs same icon index for different .exe file ....

Quote
icon index for vlc.exe      == 3
icon index for firefox.exe == 3
icon index for a.pdf         == 23
icon index for a.doc        == 12


<<

i have to identify those .exe file whose icon is like "File folder"..but if it outputs same result for all .exe file i think it will not be possible to identify .exe folder in this way ...at present there is no .exe folder(files whose icon is like file folder) in my mechine ... so i have not tested it for that kind of file ...

>>

i think for vlc.exe and firefox.exe it should generate diffent output because their icons are different ...

this is the code ... i have converted it to masm32 syntax from goAsm syntax ... hope it is ok ...



.386
.model flat, stdcall
option casemap :none

;include \masm32\include\windows.inc
;include \masm32\include\kernel32.inc
;include \masm32\include\masm32.inc
include \masm32\include\masm32rt.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\shell32.lib

.data
h_console_in         dd 0
h_console_out        dd 0
sz_Titlestring       db "Select file to get info",0
sz_1                 db "Press OK to exit",0
sz_format1           db "Icon in : %s   ",13,10,"Type of file : %s",13,10,"Index of the icon : %lu",13,10,0
junk                 dd 0
namebuffer           db 128 dup (?)
buffer               db 128 dup (?)
ofn                  OPENFILENAME <>
shfi                 SHFILEINFO <>





.code

start:



invoke GetStdHandle, STD_OUTPUT_HANDLE
mov [h_console_out], eax

invoke GetStdHandle, STD_INPUT_HANDLE
mov [h_console_in], eax

mov [ofn.lStructSize],SIZEOF ofn
mov [ofn.lpstrFile], OFFSET namebuffer
mov [ofn.nMaxFile], SIZEOF namebuffer
mov [ofn.lpstrTitle] , OFFSET sz_Titlestring
mov [ofn.Flags], OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST + OFN_EXPLORER + OFN_HIDEREADONLY + OFN_NOCHANGEDIR
invoke GetOpenFileName , addr ofn
invoke SHGetFileInfo, addr namebuffer, NULL, addr shfi, sizeof shfi, SHGFI_ICON+SHGFI_LARGEICON+SHGFI_ICONLOCATION+SHGFI_TYPENAME

invoke wsprintf, addr buffer, addr sz_format1, addr shfi.szDisplayName, addr shfi.szTypeName, [shfi.iIcon]
invoke WriteConsole, [h_console_out], addr buffer , eax, addr junk, NULL
invoke MessageBox, NULL, addr sz_1, NULL, NULL



invoke ExitProcess,0

END start






:) I have solved string matching problem ....

BlackVortex

Yeah, I noticed that,too. I don't understand what kind of icon handle that function returns, anyone have any ideas ?

What's that "system image list" the documentation referes to ?
http://msdn.microsoft.com/en-us/library/bb762179%28VS.85%29.aspx

Anyone got any ideas ?