SAMPLE: INIHEADR Sample Reads Section Headers from .INI Files

Last reviewed: February 15, 1996
Article ID: Q104096
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

The Windows SDK does not define a function to read all of the section headers from a profile (.INI) file. An application must read the entire .INI file and parse it to obtain the section headers.

NOTE: Microsoft recommends using Windows's application programming interfaces (APIs) to read .INI files. The method described below is not guaranteed to work on future releases, especially for system .INI files such as WINFILE.INI, WIN.INI, SYSTEM.INI, CONTROL.INI, and so forth.

The INIHEADR sample defines a function called GetPrivateProfileSections(), which parses a given .INI file and returns a buffer containing the section headers separated by NULLs and terminated by a double NULL. SECTION.C contains the function and a necessary helper function. The sample allows the user to choose an .INI file using the Open common dialog box. The section headings are then placed in a list box.

Download INIHEADR.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download INIHEADR.EXE (size: 29234 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get INIHEADR.EXE (size: 29234 bytes) 
    

MORE INFORMATION

A profile file (WIN.INI) or a private profile (such as CLOCK.INI) must have the following form:

   [section heading]
   entry=value
      .
      .
      .

For example, given a profile containing the following section headings

   [windows]
      .
      .
      .
   [Desktop]
      .
      .
      .
   [Extensions]

GetPrivateProfileSections() parses the profile file and places the following in a buffer:

   windows<NULL>Desktop<NULL>Extensions<NULL><NULL>


Additional reference words: 3.00 3.10 softlib INIHEADR.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrIni


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: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.