Solved

64K+ INI Files

Posted on 1999-01-22
20
415 Views
Last Modified: 2010-05-03
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
Comment
Question by:tward
  • 10
  • 5
  • 2
  • +2
20 Comments
 
LVL 3

Expert Comment

by:jjbyers
ID: 1470056
What are you storing that takes that much space?


0
 
LVL 7

Author Comment

by:tward
ID: 1470057
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
 
LVL 3

Expert Comment

by:jjbyers
ID: 1470058
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
 
LVL 15

Expert Comment

by:ameba
ID: 1470059
tward,
I checked what you said, but it works on my 92K INI.
0
 
LVL 3

Expert Comment

by:sduckett
ID: 1470060
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
 
LVL 7

Author Comment

by:tward
ID: 1470061
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
 
LVL 7

Author Comment

by:tward
ID: 1470062
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
 
LVL 1

Accepted Solution

by:
NoCheese earned 100 total points
ID: 1470063
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
 
LVL 15

Expert Comment

by:ameba
ID: 1470064
Maybe your lpReturnedString is too big?
    s = Space(2048)
    ret = GetPrivateProfileString(ApplicationName, Key, DEFAULT, s, 512, IniName)
    s = StripTerminator(s)

0
 
LVL 7

Author Comment

by:tward
ID: 1470065
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Author Comment

by:tward
ID: 1470066
ameba,

  It is stated in the Knowledge Base that the Write/GetPrivateProfileString API functions are limited to 64K INI files.
0
 
LVL 15

Expert Comment

by:ameba
ID: 1470067
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
 
LVL 7

Author Comment

by:tward
ID: 1470068
ameba,

  Are you using Windows NT/95/98?
0
 
LVL 15

Expert Comment

by:ameba
ID: 1470069
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
 
LVL 7

Author Comment

by:tward
ID: 1470070
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
 
LVL 15

Expert Comment

by:ameba
ID: 1470071
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
 
LVL 7

Author Comment

by:tward
ID: 1470072
ameba,

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

Thanks for all the help.
0
 
LVL 7

Author Comment

by:tward
ID: 1470073
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
 
LVL 1

Expert Comment

by:NoCheese
ID: 1470074
So, does that mean I get the points since that was what I suggested in the first place?
0
 
LVL 7

Author Comment

by:tward
ID: 1470075
Yeah, I accepted the answer, so you got the 100 points.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 64
Determine Range to Select 5 33
Copy a row 12 52
VB6 - Compare and highlight cell not the same 3 33
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now