|
-
May 19th, 2005, 02:56 AM
#1
Thread Starter
Member
Reading .INI files
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
-
May 19th, 2005, 01:59 PM
#2
Addicted Member
Re: Reading .INI files
Use the ReadPrivateProfileString() API.
-
May 19th, 2005, 03:37 PM
#3
Re: Reading .INI files
 Originally Posted by R.a.B.B.i.T
Use the ReadPrivateProfileString() API.
Actually I think it is called GetPrivateProfileString() 
Cheers,
RyanJ
-
May 19th, 2005, 03:49 PM
#4
Addicted Member
Re: Reading .INI files
Ah, ok. I dodn't have API-guide on this computer, so I wasn't sure; but either way, use that...
-
May 19th, 2005, 04:57 PM
#5
Re: Reading .INI files
 Originally Posted by R.a.B.B.i.T
Ah, ok. I dodn't have API-guide on this computer, so I wasn't sure; but either way, use that...
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
-
May 19th, 2005, 05:16 PM
#6
Re: Reading .INI files
i dont like how msdn uses examples..to complex for such easy things!
-
May 19th, 2005, 07:18 PM
#7
Addicted Member
Re: Reading .INI files
 Originally Posted by sciguyryan
MSDN confirmed that GetPrivateProfileString() is an API call, so that's what I went with. I also prefer allapi.net's API-Guide.
-
May 20th, 2005, 04:13 AM
#8
Thread Starter
Member
Re: Reading .INI files
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
-
May 20th, 2005, 08:18 AM
#9
Addicted Member
Re: Reading .INI files
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.
-
May 20th, 2005, 09:11 AM
#10
Thread Starter
Member
Re: Reading .INI files
yeah the VB code would be good thanks, might give me a shove in the right direction!
Wallace
-
May 20th, 2005, 11:20 AM
#11
Addicted Member
Re: Reading .INI files
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.
-
May 23rd, 2005, 03:16 AM
#12
Thread Starter
Member
Re: Reading .INI files
Thank you very much for the help. I'll let you know how i get on
wallace
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
|