softronik_
Messages postés2Date d'inscriptionlundi 8 décembre 2003StatutMembreDernière intervention 9 décembre 2003
-
9 déc. 2003 à 00:11
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 2021
-
9 déc. 2003 à 10:01
J'essaie de concaténer une variable qui contiens le path du win desktop (myWindowsDesktopDirectory) et un nom de fichier (negaShortcutName.
Ceci est supposé me donner:
C:\Documents and Settings\Administrateur\Bureau\nomfichier.lnk
mais pour des raisons qui me sont inconus, la concaténation n'est pas effectuée! Cela me donnes a la place "C:\Documents and Settings\Administrateur\Bureau"
j'ai envoyé ma source a un ami et tout semble bien fonctionner sur sa machine... SVP aidez-moi avec ce problème de niveau maternelle
Voici le code:
Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal csidl As Long, ByVal fCreate As Long) As Long
Private Const CSIDL_DESKTOPDIRECTORY = &H10
Private Const CSIDL_WINDOWS = &H24
Private Const MAX_PATH = 260
Dim myWindowsDesktopDirectory As String
Dim negaDir As String
Dim negaImageDir As String
Dim negaShortcutName As String
' Fonction qui renvoie le repertoire spécial CSIDL.
Private Function GetSpecialFolderPath(ByVal folder_number As Long) As String
Dim Path As String
Path = Space$(MAX_PATH)
If SHGetSpecialFolderPath(hwnd, Path, _
folder_number, False) _
Then
GetSpecialFolderPath = Left$(Path, InStr(Path, Chr$(0)))
Else
GetSpecialFolderPath = "???"
End If
End Function
Private Sub Form_Load()
negaDir = "\negasysteme"
negaImageDir = "\images"
negaShortcutName = "\NégaSystème.lnk"
'ici le problème....
myWindowsDesktopDirectory = GetSpecialFolderPath(CSIDL_DESKTOPDIRECTORY) & ""
Debug.Print myWindowsDesktopDirectory & negaShortcutName
End Sub
cs_EBArtSoft
Messages postés4525Date d'inscriptiondimanche 29 septembre 2002StatutModérateurDernière intervention22 avril 20199 9 déc. 2003 à 00:18
Ton erreur vient du fait que instr renvoi la position du caractere + 1 donc le caractere vbNullChar est contenu dans ta chaine donc ... erreur !
voici la solution :
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
' Fonction qui renvoie le repertoire spécial CSIDL.
Private Function GetSpecialFolderPath(ByVal folder_number As Long) As String
GetSpecialFolderPath = Space(MAX_PATH)
SHGetSpecialFolderPath hwnd, GetSpecialFolderPath, folder_number, False
GetSpecialFolderPath = Left(GetSpecialFolderPath, lstrlen(GetSpecialFolderPath))
End Function
de plus verifie la presence ou non du dernier caractere ""
avant de le forcé dans :
softronik_
Messages postés2Date d'inscriptionlundi 8 décembre 2003StatutMembreDernière intervention 9 décembre 2003 9 déc. 2003 à 04:47
Wow, j'avais par remarqué ca. Merci beaucoup. Des fois, on regarde trop juste dans un seul coin et souvent l'erreur proviens d'un autre endroit.
Top shape tout fonctionne a merveille.
Une seule choses, je voudrais savoir le CSIDL pour avoir le path du windows, il semble que CSIDL_WINDOWS qui est le &H24 ne semble me retourner rien sur Win98.