Results 1 to 5 of 5

Thread: reading all headers from ini files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Houston, Texas - U.S.A.
    Posts
    84

    reading all headers from ini files

    I'm familiar and have used the GetProfileString and WriteProfileString API calls to read and write from .ini files. Is there a way to retrieve the names of all headers in an .ini file and the name and values of the existing keys under each header?

    Thanks for your help!

  2. #2
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    Ini file is just a text file. You know all the header are inside []. Just read the file as you normally read the text file and search for all [].

    Regards.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Houston, Texas - U.S.A.
    Posts
    84
    True, but I'm looking to use the API to gather the header information - not the standard Open File for input stuff.....My API guide didn't have the API call I was looking for but I've since found it - it's the GetPrivateProfileSectionNames function. The API is much faster than the open file routine - thanks for your help!

  4. #4
    Lively Member dubae524's Avatar
    Join Date
    Jun 2001
    Location
    Currently on this Super Star Destroyer being telekinetically strangled to death by Darth Vader
    Posts
    78
    Yes. But which header information. The headers themselves? The keys, or the values? I have written a lot of non-API code on INI files. I'm right now writing instructions for using the modules, but I can post different functions if you need any help.
    - Justin Patrick Butler

    Comme je trouve. "As I find."
    - Butler family quote

    Beneficia sumptos procul superant. "The benefits far exceed the costs."
    - Myself

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Houston, Texas - U.S.A.
    Posts
    84
    Here' s what I ended up doing (I used a TreeView control to display the info):

    Code:
    Option Explicit
    
    Private Declare Function GetPrivateProfileSectionNames Lib "kernel32" _
        Alias "GetPrivateProfileSectionNamesA" (ByVal lpReturnBuffer As String, _
        ByVal nSize As Long, ByVal lpName As String) As Long
    Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias _
        "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString _
        As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
        
        
    Public Sub FillTree(strPath As String, objForm As Object)
    
        Dim strBuffer As String
        Dim lngRet As Long
        Dim arrHeaders() As String
        Dim arrValues() As String
        Dim I, J As Integer
        Dim nodParent As Node
        
        strBuffer = Space(1000)
        
        lngRet = GetPrivateProfileSectionNames(strBuffer, Len(strBuffer), strPath)
        If lngRet Then
            arrHeaders = Split(strBuffer, vbNullChar)
            For I = 0 To UBound(arrHeaders)
                Set nodParent = objForm.TreeView1.Nodes.Add(, , arrHeaders(I), arrHeaders(I))
                nodParent.Expanded = True
                
                strBuffer = Space(1000)
                lngRet = GetPrivateProfileSection(arrHeaders(I), strBuffer, Len(strBuffer), _
                    strPath)
                
                If lngRet Then
                    strBuffer = Replace(strBuffer, vbNullChar & vbNullChar, vbNullChar)
                    arrValues = Split(strBuffer, vbNullChar)
                    
                    For J = 0 To UBound(arrValues)
                        If Len(Trim(arrValues(J))) Then
                            objForm.TreeView1.Nodes.Add nodParent, tvwChild, , arrValues(J)
                        End If
                    Next
                End If
            Next
        End If
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width