Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll" Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Function EnumSections(ByRef aSections() As String, sIniPath As String) As Boolean
On Local Error Resume Next
' on récupère toutes les clés de la section
Dim sRet As String, sTempSection As String
sRet = String$(458752, vbNullChar)
sTempSection = Left$(sRet, GetPrivateProfileSectionNames(sRet, Len(sRet), sIniPath) - 1)
' en principe c'est pas vide, mais dans le doute...
If LenB(sTempSection) = 0 Then
EnumSections = False
Else
' on renvoie toutes les sections
aSections() = Split(sTempSection, vbNullChar)
EnumSections = True
End If
sRet = vbNullString
sTempSection = vbNullString
End Function
' EXEMPLE D'UTILISATION
Private Sub Form_Load()
Dim aRet() As String
If EnumSections(aRet, "C:\BOOT.INI") Then
Dim i As Integer, sRet As String
sRet = vbNullString
For i = LBound(aRet) To UBound(aRet)
sRet = sRet & "[" & aRet(i) & "]" & vbCrLf
Next i
MsgBox sRet
Else
MsgBox "aucune section"
End If
Erase aRet
Unload Me
End Sub