• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

64K+ INI Files

Is there a way to write to a 64K+ INI File?  Get/WritePrivateProfileString will only work if the INI files is less than 64K in size....
0
tward
Asked:
tward
  • 10
  • 5
  • 2
  • +2
1 Solution
 
jjbyersCommented:
What are you storing that takes that much space?


0
 
twardAuthor Commented:
Program Setup information.  Plus what does it matter what I am storing, I want to be able to get the information if it is larger than 64K.
0
 
jjbyersCommented:
This information might be better off in either a binary file or a database.

If your working in 95/98/NT most people use the registry now.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
amebaCommented:
tward,
I checked what you said, but it works on my 92K INI.
0
 
sduckettCommented:
I'm sure there are other ways but here is a possible solution just treating it as a text file:

Sub WriteToIni(Section As String, IniItem As String, ItemValue As String)

Dim IniTextLine As String
Dim SectionLength As Integer
Dim ItemLength As Integer
Dim SectionFound As Boolean
Dim ItemFound As Boolean
Dim IniFile As String
Dim TempFile As String

IniFile = "c:\MyApp.ini"
TempFile = "c:\tmp.txt"
SectionLength = Len(Trim(Section))
ItemLength = Len(Trim(IniItem))
SectionFound = False
ItemFound = False

Open IniFile For Input As #1
Open TempFile For Output As #2

Do While Not EOF(1) And Not ItemFound
    Line Input #1, IniTextLine
    If Not SectionFound And (Left(Trim(IniTextLine), SectionLength + 2) = ("[" & Trim(Section) & "]")) Then
        SectionFound = True
        GoTo NextLine
    End If
    If SectionFound Then
        If Not ItemFound And (Left(Trim(IniTextLine), ItemLength) = (Trim(IniItem))) Then
            IniTextLine = IniItem & " = " & ItemValue
            ItemFound = True
            GoTo NextLine
        End If
        If Left(IniTextLine, 1) = "[" Then
            NewTextLine = IniItem & " = " & ItemValue
            Print #2, NewTextLine
        End If
    End If
NextLine:
    Print #2, IniTextLine
Loop

Close #1
Close #2
Kill IniFile
Name TempFile As IniFile

End Sub

Now for example:
WriteToIni "Set-up", "User", "me"
replaces the value for "User" in section, "Set-up" with "me" or will add the value if it doesn't already exist.

It wouldn't take too much effort to adjust this sub to a function so that it returns values as well as writes them.
Let me know if you need any more help.
0
 
twardAuthor Commented:
Program Setup information.  Plus what does it matter what I am storing, I want to be able to get the information if it is larger than 64K.
0
 
twardAuthor Commented:
Program Setup information.  Plus what does it matter what I am storing, I want to be able to get the information if it is larger than 64K.
0
 
NoCheeseCommented:
64K is the limitation of an .INI file via the API.  To get larger than that in a settings file, you would need to resort to LESS efficient acess methods that the two API's you're currently attempting.

What I did when I hit this wall was to divide into multiple files.  I was using the .INI file format for logging of Anti-Virus updates for 5000 clients.
0
 
amebaCommented:
Maybe your lpReturnedString is too big?
    s = Space(2048)
    ret = GetPrivateProfileString(ApplicationName, Key, DEFAULT, s, 512, IniName)
    s = StripTerminator(s)

0
 
twardAuthor Commented:
jjbyers,

  I am using Win 95/98/NT but I don't want to use the registry since this limits the Setup to that machine.  I am using the program via a network and multiple machines need to run the program with the same settings.
0
 
twardAuthor Commented:
ameba,

  It is stated in the Knowledge Base that the Write/GetPrivateProfileString API functions are limited to 64K INI files.
0
 
amebaCommented:
I swear it works.
Hm, maybe it is still in cache. Or, I added commented lines which do not count? I'll try again.
0
 
twardAuthor Commented:
ameba,

  Are you using Windows NT/95/98?
0
 
amebaCommented:
Yes, it works (I merged few ini files).
Using:
Win95 (4.00.950a), IE 4.72.3110.8, VB6, Office 95
Declaration:
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

I also tried to find KB article stating what you said, but didn't find it.
0
 
twardAuthor Commented:
Although this states for Windows 3.0-3.11 it seems to apply to Windows 98.  I was having the problem on a 65K ini file, I was trying to write move stuff to it and WritePrivateProfileString was failing, as soon as I went to the DOS Editor and took some stuff out (made it abount 60K) it worked fine!

Windows: Maximum Valid Size for REG.DAT and .INI Files
Last reviewed: November 23, 1994
Article ID: Q78346  
The information in this article applies to:
Microsoft Windows operating system versions 3.0, 3.0a, 3.1, 3.11
Microsoft Windows for Workgroups versions 3.1, 3.11


SUMMARY
The maximum valid size for a REG.DAT or .INI file is 64 kilobytes (K). In some instances, however, problems occur when these files are greater than 32K.



MORE INFORMATION
If an application uses the standard Windows application program interface (API) calls to access the .INI files, the limit is 64K. Examples of these standard API calls are GetPrivateProfileString() and WritePrivateProfileString().

If, for example, the WIN.INI file exceeds 64K, the information beyond 64K is ignored, and Windows may behave unpredictably--system configuration changes may not be implemented, fonts may be missing, printer information may be missing, and default information from applications may not be saved.

If an application uses a SIGNED INT instead of an UNSIGNED INT to point to the file size, the size limit for these files is 32K. Some third-party applications may be unable to read .INI files, including the WIN.INI file, if they are larger than 32K.

NOTE: Page 89 of the "Microsoft Windows Resource Kit" (WRK) for version 3.0 incorrectly states that the maximum size of the WIN.INI file is 32K.



SysEdit
The Microsoft Windows SysEdit program provided with Windows cannot correctly edit a file larger than 30,000 bytes. If SysEdit does load a file larger than 30,000 bytes, you can delete text, but you cannot type any text until you reduce the file size to 29,999 bytes or fewer.

The largest file SysEdit can load is between 30,000 bytes and 53K, depending on your system. If you load a file large than 30,000 bytes, you may receive the following error message:


   <Filename>
   Cannot open this file.

If the large file you are trying to open is the WIN.INI file, only part of it may load, and you may receive the following two error messages:

   C:\CONFIG.SYS
   Cannot open this file

   C:\AUTOEXEC.BAT
   Cannot open this file
 


--------------------------------------------------------------------------------

KBCategory: kbtool kbdocerr
KBSubcategory: wfw wfwg win30 win31
Additional reference words: 3.00 3.00a 3.0 3.0a 3.10 3.1 3.11 documentation
error docerr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 23, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.
0
 
amebaCommented:
Thanks for this info, tward.
Sorry for confusion. I checked again, I can retrieve only items in first 64K.
What I did in my test, was, adding garbage behind real data. Real data was in first 20K of the INI file.
--
To err is human. To forgive is unusual.
0
 
twardAuthor Commented:
ameba,

  No problem, just hate it when things work for one person and not another!!!

Thanks for all the help.
0
 
twardAuthor Commented:
I ended up splitting it up into several smaller INI Files, this seems to be the only solution except for making my own, more than likely slower routines to do the Gets and Writes.

Thanks to all that helped.
0
 
NoCheeseCommented:
So, does that mean I get the points since that was what I suggested in the first place?
0
 
twardAuthor Commented:
Yeah, I accepted the answer, so you got the 100 points.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now