473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GetPrivateProfileSectionNames

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(sProfileStringBuilde r, _
sProfileStringBuilder.Capacity, sIniFile)

sProfileString = sProfileStringBuilder.ToString
GetINISectionNames = sProfileString
End Function
Nov 21 '05 #1
3 7637
Hi,

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

Ken
--------------------
"PJSimon" <PJ*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
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(sProfileStringBuilde r, _
sProfileStringBuilder.Capacity, sIniFile)

sProfileString = sProfileStringBuilder.ToString
GetINISectionNames = sProfileString
End Function
Nov 21 '05 #2
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.

"Ken Tucker [MVP]" wrote:
Hi,

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

Ken
--------------------
"PJSimon" <PJ*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
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(sProfileStringBuilde r, _
sProfileStringBuilder.Capacity, sIniFile)

sProfileString = sProfileStringBuilder.ToString
GetINISectionNames = sProfileString
End Function

Nov 21 '05 #3
On 2004-10-06, PJSimon <PJ*****@discussions.microsoft.com> wrote:
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(sProfileStringBuilde r, _
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 :).

--
Tom Shelton [MVP]
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: pcPirate | last post by:
Hi, Can anyone help me to convert the following VB6 code into C#??? Declare Function SQLSetConnectOption Lib "ODBC32.DLL" (ByVal hDbc As Long, ByVal iOption As Integer, ByVal lValue As Long)...
5
by: Andrea | last post by:
Hy I have a litle problem : I have to invoke a function in an unmanaged dll (writen in C) from C# ------------------------------------------------ int string_modify(unsigned char*...
2
by: Mike | last post by:
VB .NET version 2003 What is the equivalent of GetSetting when trying to read a .INI file. I'm trying to read a .INI file and can't find anything that will help.
3
by: Schemer | last post by:
In the .Net framework, are there functions for reading and writing the key/value pairs in a .ini file? Thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.