Gros problème de concaténation de deux string

softronik_ Messages postés 2 Date d'inscription lundi 8 décembre 2003 Statut Membre Dernière intervention 9 décembre 2003 - 9 déc. 2003 à 00:11
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 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

3 réponses

cs_EBArtSoft Messages postés 4525 Date d'inscription dimanche 29 septembre 2002 Statut Modérateur Dernière intervention 22 avril 2019 9
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 :

myWindowsDesktopDirectory = GetSpecialFolderPath(CSIDL_DESKTOPDIRECTORY) & ""
Debug.Print myWindowsDesktopDirectory & negaShortcutName

@+

E.B.
0
softronik_ Messages postés 2 Date d'inscription lundi 8 décembre 2003 Statut Membre Derniè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.
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
9 déc. 2003 à 10:01
Tu peux simplement utiliser la fonction Environ de VB...

     Environ$("windir")
    essaies, tu en as d'autres


By Renfield

[mailto:thomas_reynald@msn.com thomas_reynald@msn.com]

Aucune touche n'a ete blessee lors de la saisie de ce texte.......... ;)
0
Rejoignez-nous