Reading all keys from an ini file section

  • Thread starter Thread starter Atchoum
  • Start date Start date
A

Atchoum

Hi,

I am using the inireader class from mentalis.org but this does not provide a
function for retrieving all the key values of a particular section. Anyone
has developed such a function? I tried using the GetPrivateProfileString
function but to no avail.

TIA.
 
Hi,

I am using the inireader class from mentalis.org but this does not provide a
function for retrieving all the key values of a particular section. Anyone
has developed such a function? I tried using the GetPrivateProfileString
function but to no avail.

TIA.

What problems did you have with GetPrivateProfileString? Can you post your
attempted code?
 
Tom,

Thanks for responding.

In VB6, I had a class which used GetPrivateProfileString to get all keys
from a section using 0 as the second parameter as in:
GetPrivateProfileStringKeys(sSection, 0, "", sKeyList, Max_Entry, sFile)
This would return all keys of the sSection Section.

I have tried the same with VB.NET (although the second parameter is a
string):

Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll"
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As
StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As
Integer

dim ret as integer= GetPrivateProfileString(Section, "" , defVal, sb,
MAX_ENTRY, Filename)

I tried several options in lieu of "" but nothing seemed to work.

Atchoum
 
Tom,

Thanks for responding.

In VB6, I had a class which used GetPrivateProfileString to get all keys
from a section using 0 as the second parameter as in:
GetPrivateProfileStringKeys(sSection, 0, "", sKeyList, Max_Entry, sFile)
This would return all keys of the sSection Section.

I have tried the same with VB.NET (although the second parameter is a
string):

Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll"
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As
StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As
Integer

dim ret as integer= GetPrivateProfileString(Section, "" , defVal, sb,
MAX_ENTRY, Filename)

I tried several options in lieu of "" but nothing seemed to work.

Atchoum

here is a quick and dirty sample:

Option Strict On
Option Explicit On

Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Collections.Specialized

Module Module1

Declare Auto Function GetPrivateProfileString Lib "kernel32" _
(ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString() As Char, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer

Sub Main()

Dim keyBuffer(2047) As Char
Dim copyBuffer As New StringBuilder
Dim keys As New StringCollection
Dim nullCount As Integer = 0

Dim charsCopied As Integer = _
GetPrivateProfileString(_
"Application Control", _
Nothing, _
"", _
keyBuffer, _
keyBuffer.Length, _
"VIC4.INI")

For i As Integer = 0 To charsCopied
If keyBuffer(i) <> vbNullChar Then
nullCount = 0
copyBuffer.Append(keyBuffer(i))
Else
keys.Add(copyBuffer.ToString())
copyBuffer.Length = 0
nullCount += 1
If nullCount > 1 Then
Exit For
End If
End If
Next

For Each key As String In keys
Console.WriteLine(key)
Next
End Sub

End Module
 

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

Similar Threads

need help with Mentalis IniReader class 1
Reading an INI file 18
newbie question ?Syntax 1
Writing INI section failing 6
ini file 3
INI File 5
ini file 2 2
Output form data to a text ini file 2

Back
Top