PRB: Maximum String Lengths for .ini File APIs on Windows 95/98

ID: Q230194


The information in this article applies to:


SYMPTOMS

The Win32 functions for setting and retrieving initialization file (.ini) strings are limited to just under 32KB per read and per write on Windows 95/98. This is true for the following functions:

The actual maximum string size for these *ProfileString() functions is 2 bytes less than 32KB. The 2 bytes are used internally in the implementation of the functions.

When a *ProfileString() function fails because a string is too large, the last error value is not set. As a result, GetLastError() does not return useful information. Instead, it returns the last error value that was set before the call to *ProfileString().

The following functions are affected indirectly by this limitation (see the MORE INFORMATION section below for the details):


CAUSE

These functions were designed to handle small amounts of data. They were incorporated into the Win32 Application Programming Interface (API) merely for backward compatibility with 16-bit applications. Win32-based applications should store initialization information in the registry.


RESOLUTION

Large amounts of data should not be stored in an initialization file or in the registry, because .ini files and registry files are limited in size. For additional information about, please see the following article in the Microsoft Knowledge Base:

Q78346 Maximum Valid Size for REG.DAT and .INI Files
If your application needs to save large amounts of character data, this data should be written to another file using the File I/O APIs directly. The 16-bit APIs include _lopen(), _lread(), _lwrite(), and so on. The 32-bit APIs include CreateFile(), ReadFile(), WriteFile(), and so on.


STATUS

This behavior is by design.


MORE INFORMATION

The WritePrivateProfileStruct() and GetPrivateProfileStruct() functions can be used to set and retrieve binary data in an .ini file. The binary data is encoded to character data. Each byte of binary data maps to two bytes when encoded. The character data is then stored or retrieved from the .ini file using WritePrivateProfileString() or GetPrivateProfileString(). As a result of this encoding, the struct functions are limited to just under 16KB per read and per write on Windows 95/98. The actual maximum string size for the struct functions is 6 bytes less than 16KB. The 6 bytes are used internally in the implementation of the functions.

Additional query words:


Keywords          : kbAPI kbKernBase kbSDKWin32 kbWinOS95 kbWinOS98 kbDSupport 
Version           : winnt:
Platform          : winnt 
Issue type        : kbprb 

Last Reviewed: June 24, 1999