Comment utiliser "GetPrivateProfileString" pour renvoyer toutes les section d'un fichier de type .ini?
Comment utiliser "GetPrivateProfileString" pour renvoyer toutes les section d'un fichier de type .ini?
Je ne pense pas que ce sois possible par contre tu peux très bien lire tout ton fichier .ini et quand une ligne commence par la caractère c'est que c'est le début d'une section.
C'est un peu laborieux mais là je vois que ça.
Tu peux utiliser l'api GetPrivateProfileSectionNames.
C'est bon à savoir Catbull.
Connaissait pas. Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 Private Declare Function GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA" ( _ ByVal lpszReturnBuffer As String, _ ByVal nSize As Long, _ ByVal lpFileName As String) As Long Public Function ListeSection(Path As String, Section() As String) Dim strReturn As String strReturn = String(255, 0) GetPrivateProfileSectionNames strReturn, Len(strReturn), Path Section = Split(Left(strReturn, InStr(1, strReturn, Chr(0) & Chr(0)) - 1), Chr(0)) End Function Public Sub MainSection() Dim Section() As String ListeSection "C:\test.ini", Section For Index = LBound(Section) To UBound(Section) Debug.Print "-" & Section(Index) & "-" Next End Sub
Merci beaucoup
Est il possible d'avoir le même type de fonction qui renvoie toutes les clés d'une section donnée dans un fichier ini???
Hum ça fait longtemps que la question a été posée mais si quelqu'un peut me dire si il existe une fonction permettant de récupérer toutes les clés d'une section donnée d'un ficheir INI ça me serait bien utile
Merci!
Si quelqu'un est intéressé j'ai modifié une fonction que j'ai trouvée sur internet. Elle renvoie une string contenant tout les clés d'un section séparées par ";" (pratique pour source de combobox) :
Désolé pour les commentaires en anglais, je programme pour des anglophones Il faut bien sûr avoir déclaré la fonction GetPrivateProfileString auparavant comme expliqué dans la FAQ et dans ce sujet.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 Public Function GetSectionKeys(section As String) Dim pos As Long 'current position in section Dim nextPos As Long 'next position in section Dim currentKey As String 'current key retreived in section Dim sourceKeys As String 'keys in source string Dim buffer As String 'buffer to retrieve the section Dim size As String 'buffer size Dim retCode As Integer 'return code of GetPrivateProfileString to handle errors Dim INISection As String 'the complete section 'retrieve the complete section buffer = Space$(8192) size = Len(buffer) retCode = GetPrivateProfileString(section, 0&, "default", buffer, size, configPath) 'all the keys in the section If (size > 0) Then INISection = Left$(buffer, retCode) Else INISection = "" End If 'retrieve keys inside INISection If (Len(INISection) > 0) Then pos = 1 nextPos = InStr(pos, INISection, Chr$(0)) 'nextPos = next new line in INISection Do While nextPos <> 0 'for all the lines in the section currentKey = Mid$(INISection, pos, (nextPos - pos)) 'retrieve the key If (currentKey <> Chr$(0)) Then 'add the key to sourceKeys sourceKeys = sourceKeys & ";" & Mid$(INISection, pos, (nextPos - pos)) pos = nextPos + 1 nextPos = InStr(pos, INISection, Chr$(0)) End If Loop 'delete the first ";" in sourceKeys Dim length As Integer length = Len(sourceKeys) - 1 sourceKeys = Right$(sourceKeys, length) GetSectionKeys = sourceKeys Else 'empty INISection GetSectionKeys = "" End If End Function
Tchuss!
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager