By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Reading all keys from an ini file section

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mon, 16 Aug 2004 18:46:47 -0400, Atchoum wrote:
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 Shelton [MVP]
Nov 21 '05 #2

P: n/a
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
Nov 21 '05 #3

P: n/a
In article <Yr*********************@wagner.videotron.net>, Atchoum wrote:
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

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

This discussion thread is closed

Replies have been disabled for this discussion.