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]