Les raccourcis (Shorcut) *.lnk

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Les raccourcis (Shorcut) *.lnk

Message par Le Soldat Inconnu »

Quelques astuces pour créer et gérer des raccourcis.

A la base de ces codes, un gars du forum anglais (zappé le nom) et Nico. (pour CreateShellLink() et GetShellLinkTarget() )
J'ai juste remis propre et uniforme, j'ai ajouté la compatibilité UNICODE, et j'ai finis le lot de fonctions.

Créer un raccourci
CreateShellLink()

Lire le contenu d'un raccourci
La cible d'un raccourci : GetShellLinkTarget()
Les arguments (ou paramètres) pour lancer la cible : GetShellLinkArgument()
Le dossier d'exécution : GetShellLinkWorkingDirectory()
Le fichier qui contient l'icône du raccrouci : GetShellLinkIconFile()
Et l'index de l'icône dans le fichier : GetShellLinkIconIndex()

Code : Tout sélectionner

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_IShellLinkA :
	Data.l $000214EE
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IShellLinkW :
		Data.l $000214F9
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IPersistFile :
		Data.l $0000010B
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection

ProcedureDLL CreateShellLink(ShortcutFile.s, Target.s, Argument.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndex.l) ; Créer un raccourci
	CoInitialize_(0)
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		; The file TO which is linked ( = target for the Link )
		psl\SetPath( @Target)
		
		; Arguments for the Target
		psl\SetArguments( @Argument)
		
		; Working Directory
		psl\SetWorkingDirectory( @WorkingDirectory)
		
		; Description ( also used as Tooltip for the Link )
		psl\SetDescription( @Description)
		
		; Show command:
		; SW_SHOWNORMAL = Default
		; SW_SHOWMAXIMIZED = aehmm... Maximized
		; SW_SHOWMINIMIZED = play Unreal Tournament
		psl\SetShowCmd(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\SetHotkey(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.
		psl\SetIconLocation( @IconFile, IconIndex)
		
		; Query IShellLink For the IPersistFile interface For saving the
		; shortcut in persistent storage.
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			CompilerIf #PB_Compiler_Unicode
				; Save the link by calling IPersistFile::Save.
				hres = ppf\Save( @ShortcutFile, #True)
			CompilerElse
				; Ensure that the string is Unicode.
				Mem.s = Space(1000) ; AllocateMemory(1,1000)
				MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, -1, Mem, 1000)
				; Save the link by calling IPersistFile::Save.
				hres = ppf\Save( @Mem, #True)
			CompilerEndIf
			
			Result = 1
			ppf\Release()
		EndIf
		psl\Release()
	EndIf
	CoUninitialize_()
	ProcedureReturn Result
	
EndProcedure
ProcedureDLL.s GetShellLinkTarget(ShortcutFile.s) ; Récupérer la cible d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	#SLGP_SHORTPATH = 2
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load( @ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(Target, StringByteLength(Target), 0, #SLGP_SHORTPATH)
				EndIf
			CompilerElse
				Size.l = MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, -1, 0, 0)
				Dim unicode.w(Size)
				MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, Len(ShortcutFile), unicode(), Size)
				If ppf\Load(unicode(), #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath( @Target, 1024, 0, #SLGP_SHORTPATH)
				EndIf
			CompilerEndIf
			
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Target
	
EndProcedure
ProcedureDLL.s GetShellLinkArgument(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load( @ShortcutFile, #STGM_READ) = 0
					Argument.s = Space(1024)
					psl\GetArguments(Argument, StringByteLength(Argument))
				EndIf
			CompilerElse
				Size.l = MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, -1, 0, 0)
				Dim unicode.w(Size)
				MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, Len(ShortcutFile), unicode(), Size)
				If ppf\Load(unicode(), #STGM_READ) = 0
					Argument.s = Space(1024)
					psl\GetArguments( @Argument, 1024)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Argument
	
EndProcedure
ProcedureDLL.s GetShellLinkWorkingDirectory(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load( @ShortcutFile, #STGM_READ) = 0
					WorkingDirectory.s = Space(1024)
					psl\GetWorkingDirectory(WorkingDirectory, StringByteLength(WorkingDirectory))
				EndIf
			CompilerElse
				Size.l = MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, -1, 0, 0)
				Dim unicode.w(Size)
				MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, Len(ShortcutFile), unicode(), Size)
				If ppf\Load(unicode(), #STGM_READ) = 0
					WorkingDirectory.s = Space(1024)
					psl\GetWorkingDirectory( @WorkingDirectory, 1024)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn WorkingDirectory
	
EndProcedure
ProcedureDLL.s GetShellLinkIconFile(ShortcutFile.s) ; Récupérer le fichier icône d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load( @ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation(IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerElse
				Size.l = MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, -1, 0, 0)
				Dim unicode.w(Size)
				MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, Len(ShortcutFile), unicode(), Size)
				If ppf\Load(unicode(), #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation( @IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn IconFile
	
EndProcedure
ProcedureDLL.l GetShellLinkIconIndex(ShortcutFile.s) ; Récupérer l'index de l'icône d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load( @ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation(IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerElse
				Size.l = MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, -1, 0, 0)
				Dim unicode.w(Size)
				MultiByteToWideChar_(#CP_ACP, 0, ShortcutFile, Len(ShortcutFile), unicode(), Size)
				If ppf\Load(unicode(), #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation( @IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn IconIndex
	
EndProcedure

Ensuite, vous avez un lanceur et vous souhaitez exécuter un raccourci :
faire

Code : Tout sélectionner

RunProgram(Raccourci.s)
Ca ne fonctionne pas toujours. Entre 2 Win XP SP3, sur un ça marche, sur l'autre non.
L'erreur est bizarre, windows ne connait pas le programme pour ouvrir les fichiers *.lnk

La solution est encore plus bizarre car il faut remplacer les "\" par "\\" dans le chemin du raccourci. Comme ceci :

Code : Tout sélectionner

Fichier.s = "D:\PureBasic\Développements\Utilitaires\Barre & Menu\Barre & Menu.lnk"
RunProgram(ReplaceString(Fichier, "\", "\\", 0, 3))
Et voilà, vous pouvez tout faire avec les fichiers *.lnk
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
kwandjeen
Messages : 204
Inscription : dim. 16/juil./2006 21:44

Re: Les raccourcis (Shorcut) *.lnk

Message par kwandjeen »

Sympa le code :wink:
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Le Soldat Inconnu »

Mise à jour du code, ne marchait pas bien en Unicode
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Thyphoon
Messages : 2706
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Thyphoon »

honte a moi l'autre jour, j'ai utilisé ton code et je t'ai même pas remercié !!
Merci :mrgreen:
Avatar de l’utilisateur
Jacobus
Messages : 1559
Inscription : mar. 06/avr./2004 10:35
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Jacobus »

Petite remontée du topic car ça passe plus en PB 4.50
Dans la procédure de création de raccourci on obtient un message d'erreur indiquant qu'un string est attendu
Ici :

Code : Tout sélectionner

 ProcedureDLL CreateShellLink(ShortcutFile.s, Target.s, Argument.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndex.l) ; Créer un raccourci
   CoInitialize_(0)
   CompilerIf #PB_Compiler_Unicode
      Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
   CompilerElse
      Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
   CompilerEndIf
   If Instance = 0
      
      ; The file TO which is linked ( = target for the Link )
      psl\SetPath( @Target) <--- MAUVAIS PARAMETRE QUI PLANTE 
Une idée pour résoudre ça?
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
lepiaf31
Messages : 510
Inscription : dim. 25/mars/2007 13:44
Localisation : Toulouse, France
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par lepiaf31 »

En remplacant @Target par Target, non ?
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Les raccourcis (Shorcut) *.lnk

Message par nico »

Code : Tout sélectionner

; Version PureBasic 4.50


Interface _IShellLinkA
  QueryInterface(a, b)
  AddRef()
  Release()
  GetPath(a.i, b, c, d)
  GetIDList(a)
  SetIDList(a)
  GetDescription(a.i, b)
  SetDescription(a.p-ascii)
  GetWorkingDirectory(a.i, b)
  SetWorkingDirectory(a.p-ascii)
  GetArguments(a.i, b)
  SetArguments(a.p-ascii)
  GetHotkey(a)
  SetHotkey(a)
  GetShowCmd(a)
  SetShowCmd(a)
  GetIconLocation(a.i, b, c)
  SetIconLocation(a.p-ascii, b)
  SetRelativePath(a.p-ascii, b)
  Resolve(a, b)
  SetPath(a.p-ascii)
EndInterface


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__IShellLinkA :
  Data.l $000214EE
  Data.w $0000, $0000
  Data.b $C0, $00, $00, $00, $00, $00, $00, $46
  IID_IShellLinkW :
  Data.l $000214F9
  Data.w $0000, $0000
  Data.b $C0, $00, $00, $00, $00, $00, $00, $46
  IID_IPersistFile :
  Data.l $0000010B
  Data.w $0000, $0000
  Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection

ProcedureDLL CreateShellLink(ShortcutFile.s, Target.s, Argument.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndex.l) ; Créer un raccourci
  Protected Result.l=0,hres.i
  
  CoInitialize_(0)
  CompilerIf #PB_Compiler_Unicode
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
  CompilerElse
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID__IShellLinkA, @psl._IShellLinkA)
  CompilerEndIf
  If Instance = 0
    
    ; The file TO which is linked ( = target for the Link )
    psl\SetPath( Target)
    
    ; Arguments for the Target
    psl\SetArguments( Argument)
    
    ; Working Directory
    psl\SetWorkingDirectory( WorkingDirectory)
    
    ; Description ( also used as Tooltip for the Link )
    psl\SetDescription( Description)
    
    ; Show command:
    ; SW_SHOWNORMAL = Default
    ; SW_SHOWMAXIMIZED = aehmm... Maximized
    ; SW_SHOWMINIMIZED = play Unreal Tournament
    psl\SetShowCmd(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\SetHotkey(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.
    psl\SetIconLocation( IconFile, IconIndex)
    
    ; Query IShellLink For the IPersistFile interface For saving the
    ; shortcut in persistent storage.
    If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
      ; Save the link by calling IPersistFile::Save.
      hres = ppf\Save( ShortcutFile, #True)
      If hres=0
        Result = 1
      EndIf 
      ppf\Release()
    EndIf
    psl\Release()
  EndIf
  CoUninitialize_()
  ProcedureReturn Result
EndProcedure

ProcedureDLL.s GetShellLinkTarget(ShortcutFile.s) ; Récupérer la cible d'un raccourci
  ; Pour récupérer la cible du raccourci
  Protected Target.s
  
  CoInitialize_(0)
  
  #STGM_READ = 0
  #SLGP_SHORTPATH = 2
  
  CompilerIf #PB_Compiler_Unicode
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
  CompilerElse
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID__IShellLinkA, @psl._IShellLinkA)
  CompilerEndIf
  If Instance = 0
    If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
      If ppf\Load(ShortcutFile, #STGM_READ)=0
        Target.s = Space(1024)
        psl\GetPath(@Target, Len(Target), 0, #SLGP_SHORTPATH)
      EndIf
      ppf\Release()
    EndIf
    
    psl\Release()
  EndIf
  CoUninitialize_()
  ProcedureReturn Target
EndProcedure

ProcedureDLL.s GetShellLinkArgument(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
  ; Pour récupérer la cible du raccourci
  Protected Argument.s
  
  CoInitialize_(0)
  
  #STGM_READ = 0
  
  CompilerIf #PB_Compiler_Unicode
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
  CompilerElse
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID__IShellLinkA, @psl._IShellLinkA)
  CompilerEndIf
  If Instance = 0
    If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
      If ppf\Load(ShortcutFile, #STGM_READ) = 0
        Argument.s = Space(1024)
        psl\GetArguments( @Argument, Len(Argument))
      EndIf
      ppf\Release()
    EndIf
    psl\Release()
  EndIf
  
  CoUninitialize_()
  ProcedureReturn Argument
EndProcedure

ProcedureDLL.s GetShellLinkWorkingDirectory(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
  ; Pour récupérer la cible du raccourci
  Protected WorkingDirectory.s
  
  CoInitialize_(0)
  
  #STGM_READ = 0
  
  CompilerIf #PB_Compiler_Unicode
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
  CompilerElse
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID__IShellLinkA, @psl._IShellLinkA)
  CompilerEndIf
  If Instance = 0
    If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
      If ppf\Load(ShortcutFile, #STGM_READ) = 0
        WorkingDirectory.s = Space(1024)
        psl\GetWorkingDirectory( @WorkingDirectory, Len(WorkingDirectory))
      EndIf
      ppf\Release()
    EndIf
    psl\Release()
  EndIf
  
  CoUninitialize_()
  ProcedureReturn WorkingDirectory
EndProcedure

ProcedureDLL.s GetShellLinkIconFile(ShortcutFile.s) ; Récupérer le fichier icône d'un raccourci
  ; Pour récupérer la cible du raccourci
  Protected IconFile.s
  
  CoInitialize_(0)
  
  #STGM_READ = 0
  
  CompilerIf #PB_Compiler_Unicode
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
  CompilerElse
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID__IShellLinkA, @psl._IShellLinkA)
  CompilerEndIf
  If Instance = 0
    If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
      If ppf\Load(ShortcutFile, #STGM_READ) = 0
        IconFile.s = Space(1024)
        psl\GetIconLocation(@IconFile, Len(IconFile), @IconIndex.l)
      EndIf
      ppf\Release()
    EndIf
    psl\Release()
  EndIf
  
  CoUninitialize_()
  ProcedureReturn IconFile
EndProcedure

ProcedureDLL.l GetShellLinkIconIndex(ShortcutFile.s) ; Récupérer l'index de l'icône d'un raccourci
  ; Pour récupérer la cible du raccourci
  Protected IconFile.s
  
  CoInitialize_(0)
  
  #STGM_READ = 0
  
  CompilerIf #PB_Compiler_Unicode
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
  CompilerElse
    Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID__IShellLinkA, @psl._IShellLinkA)
  CompilerEndIf
  If Instance = 0
    If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
      If ppf\Load(ShortcutFile, #STGM_READ) = 0
        IconFile.s = Space(1024)
        psl\GetIconLocation( @IconFile, Len(IconFile), @IconIndex.l)
      EndIf
      ppf\Release()
    EndIf
    psl\Release()
  EndIf
  
  CoUninitialize_()
  ProcedureReturn IconIndex
EndProcedure
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Le Soldat Inconnu »

oui, ça donne plein d'erreur car Fred a corrigé les déclarations, revoici les fonctions :

Code : Tout sélectionner

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_IShellLinkA :
	Data.l $000214EE
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IShellLinkW :
		Data.l $000214F9
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IPersistFile :
		Data.l $0000010B
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection

ProcedureDLL CreateShellLink(ShortcutFile.s, Target.s, Argument.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndex.l) ; Créer un raccourci
	CoInitialize_(0)
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		CompilerIf #PB_Compiler_Unicode
			psl\SetPath(Target)
			psl\SetArguments(Argument)
			psl\SetWorkingDirectory(WorkingDirectory)
			psl\SetDescription(Description)
			psl\SetShowCmd(ShowCommand)
			psl\SetHotkey(HotKey)
			psl\SetIconLocation(IconFile, IconIndex)
		CompilerElse
			; The file TO which is linked ( = target for the Link )
			psl\SetPath(Target)
			
			; Arguments for the Target
			psl\SetArguments(Argument)
			
			; Working Directory
			psl\SetWorkingDirectory(WorkingDirectory)
			
			; Description ( also used as Tooltip for the Link )
			psl\SetDescription(Description)
			
			; Show command:
			; SW_SHOWNORMAL = Default
			; SW_SHOWMAXIMIZED = aehmm... Maximized
			; SW_SHOWMINIMIZED = play Unreal Tournament
			psl\SetShowCmd(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\SetHotkey(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.
			psl\SetIconLocation(IconFile, IconIndex)
		CompilerEndIf
		
		
		; Query IShellLink For the IPersistFile interface For saving the
		; shortcut in persistent storage.
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			CompilerIf #PB_Compiler_Unicode
				; Save the link by calling IPersistFile::Save.
				hres = ppf\Save(ShortcutFile, #True)
			CompilerElse
				; Save the link by calling IPersistFile::Save.
				hres = ppf\Save(ShortcutFile, #True)
			CompilerEndIf
			
			Result = 1
			ppf\Release()
		EndIf
		psl\Release()
	EndIf
	CoUninitialize_()
	ProcedureReturn Result
	
EndProcedure
ProcedureDLL.s GetShellLinkTarget(ShortcutFile.s) ; Récupérer la cible d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	#SLGP_SHORTPATH = 2
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(@Target, StringByteLength(Target), 0, #SLGP_SHORTPATH)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(Target, 1024, 0, #SLGP_SHORTPATH)
				EndIf
			CompilerEndIf
			
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Target
	
EndProcedure
ProcedureDLL.s GetShellLinkArgument(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Argument.s = Space(1024)
					psl\GetArguments(@Argument, StringByteLength(Argument))
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Argument.s = Space(1024)
					psl\GetArguments(@Argument, 1024)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Argument
	
EndProcedure
ProcedureDLL.s GetShellLinkWorkingDirectory(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					WorkingDirectory.s = Space(1024)
					psl\GetWorkingDirectory(@WorkingDirectory, StringByteLength(WorkingDirectory))
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					WorkingDirectory.s = Space(1024)
					psl\GetWorkingDirectory( @WorkingDirectory, 1024)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn WorkingDirectory
	
EndProcedure
ProcedureDLL.s GetShellLinkIconFile(ShortcutFile.s) ; Récupérer le fichier icône d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation(@IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation( @IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn IconFile
	
EndProcedure
ProcedureDLL.l GetShellLinkIconIndex(ShortcutFile.s) ; Récupérer l'index de l'icône d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation(@IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation( @IconFile, StringByteLength(IconFile), @IconIndex.l)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn IconIndex
	
EndProcedure
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Les raccourcis (Shorcut) *.lnk

Message par nico »

Au Soldat,

Pour moi ton code est faux, StringByteLength n'a rien faire ici on doit indiqué le nombre de caractères.

De plus, il y a une correction à faire sur l'une des interfaces, voir mon code précédent.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Le Soldat Inconnu »

tu as corrigé quoi sur l'interface ?

Code : Tout sélectionner

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_IShellLinkA :
	Data.l $000214EE
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IShellLinkW :
		Data.l $000214F9
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IPersistFile :
		Data.l $0000010B
		Data.w $0000, $0000
		Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection

ProcedureDLL CreateShellLink(ShortcutFile.s, Target.s, Argument.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndex.l) ; Créer un raccourci
	CoInitialize_(0)
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		CompilerIf #PB_Compiler_Unicode
			psl\SetPath(Target)
			psl\SetArguments(Argument)
			psl\SetWorkingDirectory(WorkingDirectory)
			psl\SetDescription(Description)
			psl\SetShowCmd(ShowCommand)
			psl\SetHotkey(HotKey)
			psl\SetIconLocation(IconFile, IconIndex)
		CompilerElse
			; The file TO which is linked ( = target for the Link )
			psl\SetPath(Target)
			
			; Arguments for the Target
			psl\SetArguments(Argument)
			
			; Working Directory
			psl\SetWorkingDirectory(WorkingDirectory)
			
			; Description ( also used as Tooltip for the Link )
			psl\SetDescription(Description)
			
			; Show command:
			; SW_SHOWNORMAL = Default
			; SW_SHOWMAXIMIZED = aehmm... Maximized
			; SW_SHOWMINIMIZED = play Unreal Tournament
			psl\SetShowCmd(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\SetHotkey(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.
			psl\SetIconLocation(IconFile, IconIndex)
		CompilerEndIf
		
		
		; Query IShellLink For the IPersistFile interface For saving the
		; shortcut in persistent storage.
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			CompilerIf #PB_Compiler_Unicode
				; Save the link by calling IPersistFile::Save.
				hres = ppf\Save(ShortcutFile, #True)
			CompilerElse
				; Save the link by calling IPersistFile::Save.
				hres = ppf\Save(ShortcutFile, #True)
			CompilerEndIf
			
			Result = 1
			ppf\Release()
		EndIf
		psl\Release()
	EndIf
	CoUninitialize_()
	ProcedureReturn Result
	
EndProcedure
ProcedureDLL.s GetShellLinkTarget(ShortcutFile.s) ; Récupérer la cible d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	#SLGP_SHORTPATH = 2
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(@Target, Len(Target), 0, #SLGP_SHORTPATH)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(Target, Len(Target), 0, #SLGP_SHORTPATH)
				EndIf
			CompilerEndIf
			
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Target
	
EndProcedure
ProcedureDLL.s GetShellLinkArgument(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Argument.s = Space(1024)
					psl\GetArguments(@Argument, Len(Argument))
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Argument.s = Space(1024)
					psl\GetArguments(@Argument, Len(Argument))
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Argument
	
EndProcedure
ProcedureDLL.s GetShellLinkWorkingDirectory(ShortcutFile.s) ; Récupérer l'argument d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					WorkingDirectory.s = Space(1024)
					psl\GetWorkingDirectory(@WorkingDirectory, Len(WorkingDirectory))
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					WorkingDirectory.s = Space(1024)
					psl\GetWorkingDirectory( @WorkingDirectory, Len(WorkingDirectory))
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn WorkingDirectory
	
EndProcedure
ProcedureDLL.s GetShellLinkIconFile(ShortcutFile.s) ; Récupérer le fichier icône d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation(@IconFile, Len(IconFile), @IconIndex.l)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation( @IconFile, Len(IconFile), @IconIndex.l)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn IconFile
	
EndProcedure
ProcedureDLL.l GetShellLinkIconIndex(ShortcutFile.s) ; Récupérer l'index de l'icône d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation(@IconFile, Len(IconFile), @IconIndex.l)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					IconFile.s = Space(1024)
					psl\GetIconLocation( @IconFile, Len(IconFile), @IconIndex.l)
				EndIf
			CompilerEndIf
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn IconIndex
	
EndProcedure
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Les raccourcis (Shorcut) *.lnk

Message par nico »

Si tu ajoute la modification de cette interface:

Code : Tout sélectionner

Interface _IShellLinkA 
	QueryInterface(a, b) 
	AddRef() 
	Release() 
	GetPath(a.i, b, c, d) 
	GetIDList(a) 
	SetIDList(a) 
	GetDescription(a.i, b) 
	SetDescription(a.p-ascii) 
	GetWorkingDirectory(a.i, b) 
	SetWorkingDirectory(a.p-ascii) 
	GetArguments(a.i, b) 
	SetArguments(a.p-ascii) 
	GetHotkey(a) 
	SetHotkey(a) 
	GetShowCmd(a) 
	SetShowCmd(a) 
	GetIconLocation(a.i, b, c) 
	SetIconLocation(a.p-ascii, b) 
	SetRelativePath(a.p-ascii, b) 
	Resolve(a, b) 
	SetPath(a.p-ascii) 
EndInterface 
Cela évite du code inutile:

Code : Tout sélectionner

CompilerIf #PB_Compiler_Unicode 
	If ppf\Load(ShortcutFile, #STGM_READ) = 0 
	Target.s = Space(1024) 
	psl\GetPath(@Target, Len(Target), 0, #SLGP_SHORTPATH) 
	EndIf 
CompilerElse 
	If ppf\Load(ShortcutFile, #STGM_READ) = 0 
	Target.s = Space(1024) 
	psl\GetPath(Target, Len(Target), 0, #SLGP_SHORTPATH) 
	EndIf 
CompilerEndIf 
Remplacer par:

Code : Tout sélectionner

If Instance = 0 
   If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0 
	If ppf\Load(ShortcutFile, #STGM_READ)=0 
	  Target.s = Space(1024) 
	  psl\GetPath(@Target, Len(Target), 0, #SLGP_SHORTPATH) 
	EndIf 
	ppf\Release() 
   EndIf 
   psl\Release() 
EndIf

De plus concernant les problèmes de création des raccourcis, j'ai l'impression qu'il suffit juste de mettre \\ seulement à la fin du chemin avant le nom du raccourci.
(Vu sur un exemple sur MSDN)
http://support.microsoft.com/kb/467203/fr
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Le Soldat Inconnu »

J'ai un problème sous Seven x64 avec PB en x86

quand je cherche à récupérer la cible d'un raccourci contenu dans "Program files", ça me renvoie le fichier comme si il était dans "Program files (x86)"

Bug de windows je pense mais je demande au cas ou.

Pour tester, vous créer un raccourci vers un programme de "Program files" et vous mettez le nom de votre raccourci à la fin de ce code.

Merci de votre aide

Code : Tout sélectionner

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_IShellLinkA :
	Data.l $000214EE
	Data.w $0000, $0000
	Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IShellLinkW :
	Data.l $000214F9
	Data.w $0000, $0000
	Data.b $C0, $00, $00, $00, $00, $00, $00, $46
	IID_IPersistFile :
	Data.l $0000010B
	Data.w $0000, $0000
	Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection

Procedure.s GetShellLinkTarget2(ShortcutFile.s) ; Récupérer la cible d'un raccourci
	; Pour récupérer la cible du raccourci
	CoInitialize_(0)
	
	#STGM_READ = 0
	#SLGP_SHORTPATH = 2
	#SLGP_RAWPATH = 4
	
	CompilerIf #PB_Compiler_Unicode
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkW, @psl.IShellLinkW)
	CompilerElse
		Instance = CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLinkA, @psl.IShellLinkA)
	CompilerEndIf
	If Instance = 0
		
		If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
			
			CompilerIf #PB_Compiler_Unicode
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(@Target, Len(Target), 0, #SLGP_RAWPATH)
				EndIf
			CompilerElse
				If ppf\Load(ShortcutFile, #STGM_READ) = 0
					Target.s = Space(1024)
					psl\GetPath(Target, Len(Target), 0, #SLGP_RAWPATH)
				EndIf
			CompilerEndIf
			
			
			ppf\Release()
		EndIf
		
		psl\Release()
	EndIf
	
	CoUninitialize_()
	ProcedureReturn Target
	
EndProcedure

Debug GetShellLinkTarget2("VBoxSVC.lnk")
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par flaith »

Salut

dans ta datasection tu mets des "data.b $C0", ca donne '-64' un byte va de -128 à +127, si tu mets data.c c'est pas mieux ?
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Le Soldat Inconnu »

Non, ça ne change rien du tout ... :(
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Jacobus
Messages : 1559
Inscription : mar. 06/avr./2004 10:35
Contact :

Re: Les raccourcis (Shorcut) *.lnk

Message par Jacobus »

Il faut activer le support unicode dans les options de compilation pour que ça fonctionne.
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
Répondre