blueznl wrote:1. to read a .LNK file and find out what file it is pointing to so I can find the icon
maybe this code by
bembulak is of help
(It's part of
RSBasics Win-Api-Library, but it's offline at the moment)
Code: Select all
;Autor: bembulak
EnableExplicit
Procedure ReadShellLink(File$)
Protected psl.IShellLinkA
Protected ppf.IPersistFile
Protected mem.s
Protected hres
Protected PATH$
Protected udata.WIN32_FIND_DATA
Protected Argument$
Protected WorkingDirectory$
Protected DESCRIPTION$
Protected ShowCommand.l
Protected HotKey
Protected IconFile$
Protected IconIndexInFile
Protected result
CoInitialize_(0)
If CoCreateInstance_(?CLSID_ShellLink,0,1,?IID_IShellLink,@psl.IShellLinkA) = 0
ShellLink_LOAD:
; Query IShellLink For the IPersistFile interface For loading the
; shortcut in persistent storage.
If psl\QueryInterface(?IID_IPersistFile,@ppf.IPersistFile) = 0
; Ensure that the string is Unicode.
mem.s = Space(1000) ;AllocateMemory(1,1000)
MultiByteToWideChar_(#CP_ACP, 0, File$, -1, mem, 1000)
;Save the link by calling IPersistFile::Save.
hres = ppf\Load(@mem,#True)
EndIf
Get_ShellLink_preferences:
; The file TO which is linked ( = target for the Link )
;
PATH$=Space(256)
psl\GetPath(@PATH$,Len(PATH$),udata.WIN32_FIND_DATA,0)
Debug path$
; Arguments for the Target
Argument$ = Space(256)
psl\GetArguments(@Argument$,Len(Argument$))
Debug Argument$
; Working Directory
WorkingDirectory$ = Space(256)
psl\GetWorkingDirectory(@WorkingDirectory$,Len(WorkingDirectory$))
Debug WorkingDirectory$
; Description ( also used as Tooltip for the Link )
;
DESCRIPTION$ = Space(256)
psl\GetDescription(@DESCRIPTION$,Len(DESCRIPTION$))
Debug DESCRIPTION$
; Show command:
; SW_SHOWNORMAL = Default
; SW_SHOWMAXIMIZED = aehmm... Maximized
; SW_SHOWMINIMIZED = play Unreal Tournament
ShowCommand.l = 0
psl\GetShowCmd(@ShowCommand)
; Hotkey:
; The virtual key code is in the low-order byte,
; and the modifier flags are in the high-order byte.
; The modifier flags can be a combination of the following values:
;
; HOTKEYF_ALT = ALT key
; HOTKEYF_CONTROL = CTRL key
; HOTKEYF_EXT = Extended key
; HOTKEYF_SHIFT = SHIFT key
;
psl\GetHotkey(@HotKey)
; Set Icon for the Link:
; There can be more than 1 icons in an icon resource file,
; so you have to specify the index.
;
IconFile$ = Space(256)
psl\getIconLocation(@IconFile$, Len(IconFile$),@IconIndexInFile)
Debug IconFile$
psl\Release()
ppf\Release()
EndIf
CoUninitialize_()
ProcedureReturn result
DataSection
CLSID_ShellLink:
; 00021401-0000-0000-C000-000000000046
Data.l $00021401
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
IID_IShellLink:
; DEFINE_SHLGUID(IID_IShellLinkA, 0x000214EEL, 0, 0);
; C000-000000000046
Data.l $000214EE
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
IID_IPersistFile:
; 0000010b-0000-0000-C000-000000000046
Data.l $0000010b
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
EndDataSection
EndProcedure
; CreateLink
; - TARGET$ for the Link ("c:\PureBasic\purebasic.exe")
; - LINK$ - name of the Link ("c:\pb.lnk")
; - Argument$ for the target ("%1")
; - Description$ = Description and Tooltip ("Start PureBasic")
; - Working Directory ("c:\PureBasic\")
; - Show command: #SW_SHOWNORMAL or #SW_SHOWMAXIMIZED or #SW_SHOWMINIMIZED
; - HotKey - no need to use this :)
; - IconFile + Index ( "c:\PureBasic\purebasic.exe" , 1 )
ReadShellLink("C:\abc\test.lnk")