Doers anybody know of a way to extract just the section headers from a .ini file which is in the format:
[section header 1]
data=0
data=9
[section header 2]
data=8
data=5
thank You
Printable View
Doers anybody know of a way to extract just the section headers from a .ini file which is in the format:
[section header 1]
data=0
data=9
[section header 2]
data=8
data=5
thank You
Use the ReadPrivateProfileString() API.
Quote:
Originally Posted by R.a.B.B.i.T
Actually I think it is called GetPrivateProfileString() :)
Cheers,
RyanJ
Ah, ok. I dodn't have API-guide on this computer, so I wasn't sure; but either way, use that...
Quote:
Originally Posted by R.a.B.B.i.T
Really? In that case here is a good one to have a look at :)
ftp://ftp.cs.virginia.edu/pub/lcc-win32/win32hlp.exe
Quite big at 12.8 Megabytes though, but worth it :) (Also, check out MSDN too)
Cheers,
RyanJ
i dont like how msdn uses examples..to complex for such easy things!
MSDN confirmed that GetPrivateProfileString() is an API call, so that's what I went with. I also prefer allapi.net's API-Guide.Quote:
Originally Posted by sciguyryan
Thanks for the help. I've looked at the api-guide and I have decided to try using GetPrivateProfileSectionNames(). It seems to work but I have another question which I think is probably quite funamental in C++.
How do I retrieve each individual null terminated string from the returned buffer containing each section name? My intention is to put them into a listbox.
Thanks
Wallace
I don't have any C++ code for that at the moment, but I have some VB6 code (I really don't feel like porting) if you want.
yeah the VB code would be good thanks, might give me a shove in the right direction!
Wallace
VB Code:
Public Function GetStuff(sFile As String, appname As String, Key As String) As String Dim sDefault As String Dim lSize As Integer Dim l As Long Dim sUser As String On Error GoTo GetStuff_Error sUser = Space$(128) lSize = Len(sUser) sFile = App.Path & "\" & sFile & ".ini" sDefault = "" l = GetPrivateProfileString(appname, Key, sDefault, sUser, lSize, sFile) sUser = Mid(sUser, 1, InStr(sUser, Chr(0)) - 1) GetStuff = sUser On Error GoTo 0 Exit Function GetStuff_Error: AddC vbRed, "GetStuff() Call Error:" & _ vbNewLine & "Error: " & Err.Number & _ vbNewLine & "Description: " & Err.Description & _ vbNewLine & "Source: " & Err.Source End Function
Use:VB Code:
Dim k As String k = GetStuff("somefile", "someheader", "somefield")
AddC() is a function I wrote to add text to a RTB, so just ignore that bit.
Thank you very much for the help. I'll let you know how i get on
wallace