News:

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

Icon--FullPathName

Started by ic2, August 12, 2008, 06:08:18 AM

Previous topic - Next topic

ic2

Is there a way to get the FullPathName of an icon on the desktop including any (selected) icons inside folders.   Everytime we click a icon in a folder, information is dispayed in the Status Bar about the file or shortcut selected.  Class_Name msctls_statusb.  Shortcut will display Location: FullPathName.   My Computer will display Free Space: 1.24 GB.  Files will display Type: Text Document. Folders displays 1 objects selected.   Desktop displays nothing, I don't think.

Somewhere under all of this is the FullPathName stored in a structure somewhere.  How can I retrive the string with the FullPathName the second a user click to select a object than save them to my own structure.  Also if I must use a hook,  what type would I need.

Thanks in advance

donkey

The IShellLink interface will give the fully qualified path to a shortcuts target if thats what you're looking for...

.DATA
IID_IShellLink GUID <0000214eeh, 00000h, 00000h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 046h>
CLSID_ShellLink GUID <000021401h, 00000h, 00000h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 046h>
IID_IPersistFile GUID <00000010bH, 00000H, 00000H, 0C0H, 000H, 000H, 000H, 000H, 000H, 000H, 046H>

.CODE

ResolveLink FRAME hwnd,lpLinkPath,fFlags
uses ebx
LOCAL psl :D
LOCAL ppf :D
LOCAL pwsz :D

xor ebx,ebx

// Allocate memory to hold the Unicode link path
invoke CoTaskMemAlloc,MAX_PATH*2
mov [pwsz],eax
test eax,eax
jnz >
dec eax
ret
:

// Create an instance of IShellLink
invoke CoCreateInstance, offset CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, \
offset IID_IShellLink, offset psl
mov ebx,eax
test eax,eax
jnz >>.EXIT

// Get a pointer to the IPersistFile interface of IShellLink
CoInvoke(psl,IShellLink.IUnknown.QueryInterface, offset IID_IPersistFile, offset ppf)
mov ebx,eax
test eax,eax
jnz >.ReleaseIShellLink

// Convert the link path provided to Unicode
invoke MultiByteToWideChar, CP_ACP, NULL, [lpLinkPath], -1, [pwsz], MAX_PATH

// Call the IPersistFile::Load method to open the file object
CoInvoke(ppf,IPersistFile.Load, [pwsz], STGM_READ)
mov ebx,eax
test eax,eax
jnz >.ReleaseAll

// A window handle must be provided, if NULL then use the desktop window
mov eax,[hwnd]
test eax,eax
jnz >
invoke GetDesktopWindow
:

// Call IShellLink::Resolve to search for a likely link target
CoInvoke(psl,IShellLink.Resolve,eax,[fFlags])
mov ebx,eax

.ReleaseAll
// Release the IPersistFile interface
CoInvoke(ppf,IPersistFile.IUnknown.Release)

.ReleaseIShellLink
// Release the IShellLink interface
CoInvoke(psl,IShellLink.IUnknown.Release)

.EXIT
// Free the memory used to hold the Unicode path
invoke CoTaskMemFree,[pwsz]

mov eax,ebx
RET
ENDF


As for real time monitoring of user selections I am not aware of an interface that would allow you to do that, the only one that is close is the IContextMenu interface but that requires the user to select a menu item. However I have seen software that seems to do this, I'm just not sure how it does.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ic2

If this style code (with my code added) will give the full qualified path name at the time when a user press left button down on any icon than it is EXACTLY what I need.  Never for real time monitoring but only to let my app know that something **MAY** be comming my way, such as a drag & drop.

No need for Windows DragDrop Messages when I do a few tricks before and after your code.  I'll have the FullPathName waiting in the cut ...  I'm working with it right now.  Is there any addition advice I can use to meet this goal.

if Not ...


THANK YOU again donkey

My next question is what can we possibly do for our  Assembler Gods

ic2

I'm having trouble with this one line of code.  I think I got everything else translated to FASM style coding correctly.  It all based on usecom example.  I think it needs comcall but not sure how to translate it and I don't want to miss out on a possible solution.  After this, I think I got it.

CoInvoke(psl,IShellLink.IUnknown.QueryInterface, offset IID_IPersistFile, offset ppf)

Thanks in advance


http://edndoc.esri.com/arcobjects/9.1/ArcGISDevHelp/DevelopmentEnvs/COM/IntroToCOM.htm

donkey

Hi ic2,

I posted this early inthe morning here and I included the wrong procedure, this (the original) resolve link procedure will attempt to find the file associated with a broken shortcut though for your purposes it should work as you want it to, this is the proper way from my Files.Lib library, my libs don't use my CoInvoke Macro so they can be translated more easily...

/*ResolveLink:
Resolves a shortcut returning the path of the target file
Parameters:
lpbuffer = Buffer in which the path is returned
lpLinkPath = Fully qualified path to the LNK file
The lpbuffer and lpLinkPath can point to the same buffer, in which case the
Link target will be copied over the link file buffer.
CoInitialize must be called at some point in your program before this function
Returns 0 if successful

Tested GoAsm & MASM*/

ResolveLink FRAME lpbuffer,lpLinkPath
uses edi
LOCAL psl :D
LOCAL ppf :D
LOCAL pwsz :D

invoke GlobalAlloc,40h,540
mov [pwsz],eax

invoke CoCreateInstance, addr CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,ADDR IID_IShellLink,addr psl
cmp eax,S_OK
je >
push eax
jmp >>O1
:

lea eax,ppf
push eax
lea eax,IID_IPersistFile
push eax
push [psl]
mov edi,[psl]
mov edi,[edi]
call [edi+IShellLink.IUnknown.QueryInterface]
cmp eax,S_OK
je >
push eax
jmp >P1
:

invoke MultiByteToWideChar,CP_ACP,NULL,[lpLinkPath],-1,[pwsz],MAX_PATH

push STGM_READ
push [pwsz]
push [ppf]
mov edi,[ppf]
mov edi,[edi]
call [edi+IPersistFile.Load]
cmp eax,S_OK
je >
push eax
jmp >A1
:

push NULL
push NULL
push MAX_PATH
push [lpbuffer]
push [psl]
mov edi,[psl]
mov edi,[edi]
call [edi+IShellLink.GetPath]
cmp eax,S_OK
je >
push eax
jmp >A1
:
push S_OK

A1: ;AllDone:
push [ppf]
mov edi,[ppf]
mov edi,[edi]
call [edi+IPersistFile.IUnknown.Release]

P1: ;NoPersist:
push [psl]
mov edi,[psl]
mov edi,[edi]
call [edi+IShellLink.IUnknown.Release]

O1: ;OleBad:
invoke GlobalFree,[pwsz]
pop eax

   ret
endf


If you need the CoInvoke macro definition, it is included below...

CoInvoke(%pInterface,%Method,%0,%1,%2,%3,%4,%5,%6,%7,%8,%9) MACRO
#IF ARGCOUNT = 12
push %9
#ENDIF
#IF ARGCOUNT > 10
push %8
#ENDIF
#IF ARGCOUNT > 9
push %7
#ENDIF
#IF ARGCOUNT > 8
push %6
#ENDIF
#IF ARGCOUNT > 7
push %5
#ENDIF
#IF ARGCOUNT > 6
push %4
#ENDIF
#IF ARGCOUNT > 5
push %3
#ENDIF
#IF ARGCOUNT > 4
push %2
#ENDIF
#IF ARGCOUNT > 3
push %1
#ENDIF
#IF ARGCOUNT > 2
push %0
#ENDIF
push [%pInterface]
mov eax, [%pInterface]
mov eax,[eax]
add eax, %Method
call [eax]
ENDM
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ic2

QuoteCoInitialize must be called at some point in your program before this function Returns 0 if successful

How about if I create a mouse hook that catch the WM_MOUSEDOWN message on a icon to triger my app to call CoInitialize.  I guest from there I have to play with a timer or light-weight threads until I find that point of return.  Do you think this might work.  Also, what do your first posted code do.  I been fixing it up with names that I can catch onto and reading the Win32 and Fasm help files as I go.  I been wondering how to do it for weeks trying difference ideas.  Things I know nothing about. Then when I thought about Windows Status Bar messages and properties sheets, the word impossible was than out the question.  Now it's a matter of knowing which way to go.  I was thinking COM and I be darn that is what you answered with. So much more to learn.  I guest it's to late to quit now... My mind been blown again.

ic2

donkey, what kind of value does CoCreateInstance return.  I notice  cmp eax, S_OK.    Never seen nothing like that before, so instead of guesting I better ask to be sure.  What's in  S_OK already?  I just finsh translating the COMINVK and COMCALL macros to pure assembler this morning.  Looking at your code and what I came up with, they almost look IDENTICAL and I did'nt cheat.  I think all I'll end up doing tonight is the brackets thing and I bet it will work on first run.  Than I want to see my B+ on my report card :) ... FINALLY

Thanks again donkey




PBrennick

ic2,

Be adventurous, look around, this is from windows.inc:

Quote
S_OK                                  equ 0h
S_FALSE                             equ 1h

-- Paul
The GeneSys Project is available from:
The Repository or My crappy website

ic2

You're right.  I forgot.  From day25 i only use include to get value and write it in the code with the name comment out.  Writing in direct values turn out to be a bad habit because now all new samples i see looks so stranges.  I do it because I like to see all of the code on the page.  Not using the stroll bar is nice.  That's the only reason I don't invoke is because I need visible comment space.  Funny, I was totally lost.  And playing with fasm macros is making me worse.  Thanks PBrennick

   invoke CreateWindowEx,0,btnClass,btnText1,\
   40000000h or 10000000h or 1, 20,20,60,30,hwnd,i1,0,0  


   PUSH  ebx                            ;  s_ITaskBar
   PUSH  IID_ITaskbarList         ;  <56FDF342>
   PUSH  1                                ;   CLSCTX_INPROC_SERVER
   PUSH  0                                ;   NULL
   PUSH  CLSID_TaskbarList      ;  <56FDF344>
   CALL  CoCreateInstance              

cmp eax, 0h

cmp eax, _TEMP

Farabi

From where I can get this value and what does it mean?

.DATA
IID_IShellLink GUID <0000214eeh, 00000h, 00000h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 046h>
CLSID_ShellLink GUID <000021401h, 00000h, 00000h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 046h>
IID_IPersistFile GUID <00000010bH, 00000H, 00000H, 0C0H, 000H, 000H, 000H, 000H, 000H, 000H, 046H>


This is what is called by COM right?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

ic2

As you see I am really new to this too.  Here's a sample donkey gave me a while back.  It was in GoAsm.  I translated it to MASM.  I don't know where to get the meaning of values but maybe this will show you how to use the values.  That is a good question ???  Here's a wikipedia but it better hearing it  from people of experence.

http://en.wikipedia.org/wiki/Globally_Unique_Identifier

[attachment deleted by admin]

lingo

It was in GoAsm.  I translated it to MASM."
I re-translated it to "pure" MASM...  :lol
.386   
.model      flat, stdcall
option      casemap:none

;     include files
;     ~~~~~~~~~~~~~
      include c:\masm32\include\windows.inc
      include c:\masm32\include\user32.inc
      include c:\masm32\include\kernel32.inc
      include c:\masm32\include\ole32.inc

;     libraries
;     ~~~~~~~~~
      includelib c:\masm32\lib\user32.lib
      includelib c:\masm32\lib\kernel32.lib
      includelib c:\masm32\lib\ole32.lib

Unknown STRUCT
QueryInterface      DWORD ?
AddRef              DWORD ?
Release            DWORD ?
Unknown ends

ITaskbarList STRUCT
IUnknown Unknown <>
HrInit DWORD ?
AddTab                  DWORD ?
DeleteTab DWORD ?
ActivateTab DWORD ?
SetActiveAlt DWORD ?
ITaskbarList ends

GUID STRUCT
    Data1 dd ?
Data2 dw ?
Data3 dw ?
Data4 db 8 dup(?)
GUID ENDS


.const
BTN_ONE     equ 101
IDC_EDIT    equ 102
BTN_TWO     equ 103

sCLSID_TaskbarList textequ <{056fdf344H, 0fd6dH, 011D0H,\
{095H, 08ah, 000H, 060H, 097H, 0c9H, 0a0H, 090H}}>
sIID_ITaskbarList textequ <{056FDF342H, 0FD6DH, 011D0H,\
{095H, 08AH, 000H, 060H, 097H, 0C9H, 0A0H, 090H}}>

.data
szDlg        db   "DLG", 0
CLSID_ITaskbarList  GUID        sCLSID_TaskbarList
IID_ITaskbarList    GUID        sIID_ITaskbarList

.data?
ptb dword  ?

.code                                 
Start:           
mov ecx, offset DlgProcedure
invoke DialogBoxParam, 400000h, addr szDlg, 0, ecx, 0
Invoke ExitProcess, 0

DlgProcedure:
; RetAddr->[esp+0*4], hDlg->[esp+1*4], uMsg->[esp+2*4], wParam->[esp+3*4], lParam->[esp+4*4]

cmp dword ptr [esp+2*4], WM_CLOSE
jne @f
mov ecx, [esp+1*4] ; hDlg
invoke EndDialog, ecx, 0
L_Default:
xor eax, eax
ret     4*4
@@:
cmp dword ptr [esp+2*4], WM_COMMAND
jne L_Default
cmp word ptr [esp+3*4+2], BN_CLICKED
jne L_Default

push edi
push esi
        invoke CoInitialize, 0
        invoke CoCreateInstance, addr CLSID_ITaskbarList, 0, \
                        CLSCTX_INPROC_SERVER, addr IID_ITaskbarList, addr ptb
cmp eax, S_OK
        jne L_exit
mov eax, ptb
push ptb
mov edi, [eax]
call [edi].ITaskbarList.HrInit
        cmp eax, S_OK
        jne L_Error_exit
mov ecx, [esp+1*4+2*4] ; hDlg
mov eax, [edi].ITaskbarList.AddTab
cmp word ptr [esp+3*4+2*4], BTN_TWO
push ecx ; hDlg
push ptb
je @f
        mov eax, [edi].ITaskbarList.DeleteTab
@@:
call eax
L_exit:
mov esi, eax
push ptb
call [edi].ITaskbarList.IUnknown.Release
invoke CoUninitialize
xor eax, eax ; exit without error-> eax = 0
cmp esi, S_OK
je @f
L_Error_exit:
or eax, -1 ; exit with error-> eax = -1
@@:
pop esi
pop edi
ret  4*4
End Start

donkey

GUIDs or Globally Unique IDentifiers are used in various parts of Windows for many different purposes, one of those is COM. Since with COM you don't need to know what DLL holds the function you are interested in or whether it is spread out over multiple DLLs or even a name for the library of functions, you have to have a way to uniquely identify it to Windows. When you register a server using DLLRegisterServer your COM server passes the GUID to Windows and it is added to the registry with the information needed to start and execute the function as well as quite a bit more if you want it. GUIDs are available in the Windows header files, they are pretty much all defined and available in my headers for GoAsm, I generally include them in snippets and samples so anyone interested doesn't need to go searching for them.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable