From: Jimekus on
I've replaced my registry entries using an ini file, but I've just
discovered that I can only have 254 bytes of text stored in a key, or
half that for unicode, so without having to use another file
structure, I want to find another function that supports greater
lengths.
From: Ralph on

"Jimekus" <jimekus(a)gmail.com> wrote in message
news:a8f69a99-1d9a-40e8-af92-c0cd34cf7fbf(a)h14g2000pri.googlegroups.com...
> I've replaced my registry entries using an ini file, but I've just
> discovered that I can only have 254 bytes of text stored in a key, or
> half that for unicode, so without having to use another file
> structure, I want to find another function that supports greater
> lengths.

There isn't one. "256" is a hard limitation. (INI files are also limited in
size - total of all keys and values must be less than 64k)

Your choice of a substitute depends on whether this data is to be shared
between several application while they are running, or simply a persistent
store between runs.

For example, you could simply write your own "INI-like" database - but then
it wouldn't be managed by the O/S. (You'd have to create your manager.). It
this store is only for persistance - then you might create your own
serialization to a file. and so on.

-ralph





From: Nobody on
"Jimekus" <jimekus(a)gmail.com> wrote in message
news:a8f69a99-1d9a-40e8-af92-c0cd34cf7fbf(a)h14g2000pri.googlegroups.com...
> I've replaced my registry entries using an ini file, but I've just
> discovered that I can only have 254 bytes of text stored in a key, or
> half that for unicode, so without having to use another file
> structure, I want to find another function that supports greater
> lengths.

Try XML files.


From: Nobody on
"Ralph" <nt_consulting64(a)yahoo.com> wrote in message
news:usQB6lWdKHA.5984(a)TK2MSFTNGP06.phx.gbl...
>
> "Jimekus" <jimekus(a)gmail.com> wrote in message
> news:a8f69a99-1d9a-40e8-af92-c0cd34cf7fbf(a)h14g2000pri.googlegroups.com...
>> I've replaced my registry entries using an ini file, but I've just
>> discovered that I can only have 254 bytes of text stored in a key, or
>> half that for unicode, so without having to use another file
>> structure, I want to find another function that supports greater
>> lengths.
>
> There isn't one. "256" is a hard limitation. (INI files are also limited
> in
> size - total of all keys and values must be less than 64k)

I found by testing that INI section size is not limited to 64K, at least on
NT4/2000/XP/Vista/7. I made a single section and the file size is few
hundred KB. I tested both read/write to values that reside beyond 64KB in
these OS'es. All values are unique. I realize that this is undocumented, so
there maybe limitations in some systems, or could be limited in the future.
Here is sample code. To try it, in Form1, add three buttons with the
following names.

btnStart
btnPause
btnRead

And a label "lblStatus", then use the following code. Click Start, then
click Pause after the INI file has grown to a large size, and at least to
10000 entries. Click Read to show the 10000 entry value. If you click Start
again, it would resume adding entries.


Option Explicit

Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias _
"GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal nDefault As Long, _
ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias _
"GetPrivateProfileSectionA" (ByVal lpAppName As String, _
ByVal lpReturnedString As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Long

Dim m_bPause As Boolean
Dim LastValue As Long

Private Sub btnStart_Click()
Dim i As Long
Dim s As String
Dim ret As Long
Dim t As Single

btnStart.Enabled = False
m_bPause = False
t = Timer
If LastValue = 0 Then
LastValue = 1
End If
For i = LastValue To 2000000000
ret = WritePrivateProfileString("Config", "i" & Format(i, _
"00000000"), "Test" & Format(i, "00000000"), _
App.Path & "\Test.ini")
If ret = 0 Then
s = "WritePrivateProfileString failed with error " & _
Err.LastDllError & " i = " & i
Debug.Print s
MsgBox s
Exit For
End If
If i Mod 1000 = 0 Then
lblStatus.Caption = Str(i) & ", Time: " & Str(Timer - t)
DoEvents
End If
If m_bPause Then
Exit For
End If
Next

LastValue = i
End Sub

Private Sub btnPause_Click()
m_bPause = True
btnStart.Enabled = True
End Sub

Private Sub btnRead_Click()
Dim i As Long
Dim s As String
Dim ret As Long

' Read "i00010000" value

s = Space(100)
ret = GetPrivateProfileString("Config", "i" & Format(10000, _
"00000000"), "", s, 100, App.Path & "\Test.ini")
If ret = 0 Then
s = "GetPrivateProfileString failed with error " & _
Err.LastDllError
Debug.Print s
MsgBox s
Else
s = Left(s, ret)
MsgBox "Sucess, value = '" & s & "'"
End If
End Sub




From: Jimekus on
On Dec 5, 6:09 pm, "Ralph" <nt_consultin...(a)yahoo.com> wrote:
> "Jimekus" <jime...(a)gmail.com> wrote in message
>
> news:a8f69a99-1d9a-40e8-af92-c0cd34cf7fbf(a)h14g2000pri.googlegroups.com...
>
> > I've replaced my registry entries using an ini file, but I've just
> > discovered that I can only have 254 bytes of text stored in a key, or
> > half that for unicode, so without having to use another file
> > structure, I want to find another function that supports greater
> > lengths.
>
> There isn't one. "256" is a hard limitation. (INI files are also limited in
> size - total of all keys and values must be less than 64k)
>
> Your choice of a substitute depends on whether this data is to be shared
> between several application while they are running, or simply a persistent
> store between runs.
>
> For example, you could simply write your own "INI-like" database - but then
> it wouldn't be managed by the O/S. (You'd have to create your manager.). It
> this store is only for persistance - then you might create your own
> serialization to a file. and so on.
>
> -ralph

Thanks. In the meantime for my .Filename list of images from
a .FileOpen call, I've reverted to the unlimited lengths provided by
SaveSetting and GetSetting, you know the string of filenames separated
by quotes.

However, it strikes me that there must be another DLL out there to
handle longer strings as Google's .Picasa.ini uses the same format for
storing image lists and captions. I doubt they would restrict captions
to 128 unicode characters and not tell anybody.