|
-
Jul 31st, 2001, 03:57 PM
#1
Thread Starter
Lively Member
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!
-
Jul 31st, 2001, 05:52 PM
#2
Fanatic Member
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.
-
Aug 1st, 2001, 12:28 PM
#3
Thread Starter
Lively Member
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!
-
Aug 5th, 2001, 10:19 AM
#4
Lively Member
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
-
Aug 6th, 2001, 04:17 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|