Partially fixed...now a new problem.
I knew as soon as I posted a message, I'd make some headway.
I used to have to function declarations, one for the Null value and one to accept a key name (GetPrivateProfileStringNullKey and GetPrivateProfileKey) but I found out I could eliminate the Null one and just use GetPrivateProfileKey:
Code:
Declare Function GetPrivateProfileStringKey Lib "kernel32" _
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
If I pass in a key name for lpKeyName, I get the corresponding value of that key in lpReturnedString. For the Null case, I'm passing vbNullString instead of a key name. I also decided to use the StringBuilder class instead of string. My problem now is that when I pass vbNullString to the function, it returns the proper length in nLen (see below), but it only returns the first key (only 4 characters) in lpReturntedString. I should be getting 612 characters in that string for my particualr case. Here's the code I now have:
Code:
Dim sKeyNames As New StringBuilder(30002)
Dim sDefault As String
Dim nLen As Integer
' Get all key names for a section in file
' Keys names are seperated by Chr(0),
' last key name is followed two Chr(0) characters
sDefault = ""
nLen = GetPrivateProfileStringKey(sSectionName, vbNullString, sDefault, _
sKeyNames, 30000, sFileName)
Any thoughts on why it's only returning the first key and not all of the keys?
Thanks!
Dave
Re: GetPrivateProfileString - found another error
Hi,
I searched also for the error, because I always got back an empty string. I have tried a little bit:
Just let the first line of the .ini-file empty to avoid this error.
After that It worked fine (I also used the long->integer exchange, string->
System.Text.StringBuilder).
Hope that helped...