GetPrivateProfileSectionNames

G

Guest

I know, I know. INI files are officially bad now. Regardless, I have a
question about the GetPrivateProfileSectionNames function in vb.net.

When I call the function, I am only getting the first section of the INI
file, not all the sections. I can't figure out why (yes, the INI file has
more than one section).

Thanks in advance,
PJSimon

************************
Private Declare Ansi Function GetPrivateProfileSectionNames Lib
"kernel32.dll" _
Alias "GetPrivateProfileSectionNamesA" _
(ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer

Public Const PS_SIZE = 2000

Public Function GetINISectionNames(ByVal sIniFile As String) As String
Dim sProfileStringBuilder As New StringBuilder(PS_SIZE)
Dim sProfileString As String
Dim iRc As Integer

sProfileString = Space(PS_SIZE)
iRc = GetPrivateProfileSectionNames(sProfileStringBuilder, _
sProfileStringBuilder.Capacity, sIniFile)

sProfileString = sProfileStringBuilder.ToString
GetINISectionNames = sProfileString
End Function
 
K

Ken Tucker [MVP]

Hi,

Free class for reading ini files.
http://www.mentalis.org/soft/class.qpx?id=6

Ken
--------------------
I know, I know. INI files are officially bad now. Regardless, I have a
question about the GetPrivateProfileSectionNames function in vb.net.

When I call the function, I am only getting the first section of the INI
file, not all the sections. I can't figure out why (yes, the INI file has
more than one section).

Thanks in advance,
PJSimon

************************
Private Declare Ansi Function GetPrivateProfileSectionNames Lib
"kernel32.dll" _
Alias "GetPrivateProfileSectionNamesA" _
(ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer

Public Const PS_SIZE = 2000

Public Function GetINISectionNames(ByVal sIniFile As String) As String
Dim sProfileStringBuilder As New StringBuilder(PS_SIZE)
Dim sProfileString As String
Dim iRc As Integer

sProfileString = Space(PS_SIZE)
iRc = GetPrivateProfileSectionNames(sProfileStringBuilder, _
sProfileStringBuilder.Capacity, sIniFile)

sProfileString = sProfileStringBuilder.ToString
GetINISectionNames = sProfileString
End Function
 
G

Guest

One kind fellow on this newsgroup, I don't remember his name, suggested, what
I think is a really slick way to store initialization data. Create a class
that is serializable and has all the variables you want to store which can be
accessed by various properties or whatever. When the program ends, serialize
it to a filestream. When the program restarts, deserialize it and you can
read your variables via the class properties or directly if they are public.
Hopes this gives you some ideas.
 
T

Tom Shelton

I know, I know. INI files are officially bad now. Regardless, I have a
question about the GetPrivateProfileSectionNames function in vb.net.

When I call the function, I am only getting the first section of the INI
file, not all the sections. I can't figure out why (yes, the INI file has
more than one section).

Thanks in advance,
PJSimon

************************
Private Declare Ansi Function GetPrivateProfileSectionNames Lib
"kernel32.dll" _
Alias "GetPrivateProfileSectionNamesA" _
(ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer

Public Const PS_SIZE = 2000

Public Function GetINISectionNames(ByVal sIniFile As String) As String
Dim sProfileStringBuilder As New StringBuilder(PS_SIZE)
Dim sProfileString As String
Dim iRc As Integer

sProfileString = Space(PS_SIZE)
iRc = GetPrivateProfileSectionNames(sProfileStringBuilder, _
sProfileStringBuilder.Capacity, sIniFile)

sProfileString = sProfileStringBuilder.ToString
GetINISectionNames = sProfileString
End Function

If I remember correctly this API call returns the section names
separated by double null chars. The marshaller will only marshall up to
the first null char. You'll need to use a byte array (actually, a char
array might work - but I'm not on windows to try it out :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top