How to Read Information from Windows .INI Files

Last reviewed: April 29, 1996
Article ID: Q102564
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6x

SUMMARY

The examples below demonstrate how to read specific information from the Windows .INI files. The first example shows how to read information from the WIN.INI file; the second example shows how to read information from any other Windows .INI file.

NOTE: This article only applies to 16-bit versions of Microsoft Windows (Windows versions 3.x).

MORE INFORMATION

Example 1

This example will read the Load= line from the [Windows] section of the WIN.INI file:

\kbon

   SET LIBRARY TO SYS(2004)+"FOXTOOLS.FLL"
   MRETURN=REPLICATE(CHR(0), 144)
   MREGISTER=REGFN("GETPROFILESTRING","CCC@CI","I")
   MCALL=CALLFN(MREGISTER,"WINDOWS","LOAD","",@MRETURN,256)
   WAIT WINDOW ALLTRIM(MRETURN)
\kboff

MRETURN is created as a large and empty character variable. This variable is required when calling a function like this one. If we were to omit the line to set up this variable, the function would not work. MRETURN can also be initialized by using SPACE(144) instead of using REPLICATE().

MREGISTER is the variable name that defines the function using the RegFn() function. This example registers the GetProfileString() function and returns a value from the WIN.INI file.

MCALL returns a numeric value after calling the MREGISTER() function. The number returned is the length of the returned string. MRETURN is still going to be the full length that it was originally created.

This example returns the setting of the Load= line under the [Windows] section of the WIN.INI file. If the Load= line does not contain any information, the Default Return value, specified in the MCALL statement after the "LOAD" key name, returns nothing and MCALL equals zero. The Default Return value can be modified to return any character expression.

To read a different section of the WIN.INI file, change "WINDOWS" in the example above to the application name of the section to be read from (for example, "DESKTOP" would indicate the [Desktop] section). In addition, change "LOAD" to reflect the key name to be read (for example, "WALLPAPER" would indicate the Wallpaper= line under the [Desktop] section).

NOTE: Application name and key name are not case sensitive.

Example 2

This example will read the Color Schemes= line from the [Current] section of the CONTROL.INI file:

\kbon

   SET LIBRARY TO SYS(2004)+"FOXTOOLS.FLL"
   MRETURN=REPLICATE(CHR(0), 144)
   MREGISTER=REGFN("GETPRIVATEPROFILESTRING","CCC@CIC","I")
   MCALL=CALLFN(MREGISTER,"CURRENT","COLOR SCHEMES", ;
      "",@MRETURN,256,"CONTROL.INI")
   WAIT WINDOW ALLTRIM(MRETURN)
\kboff

NOTE: The MCALL lines should be combined to fit on one line.

The commands are almost the same as those in Example 1, except that this example uses the GetPrivateProfileString() function. This function allows any Windows .INI file, other than the WIN.INI file, to be read. Another difference between this example and Example 1 is that you must specify the .INI file to be read. By default, if no path is specified, Windows will look in the Windows program directory (usually C:\WINDOWS) for the .INI file.

REFERENCES

Microsoft Windows Software Development Kit "Guide to Programming," version 3.1


Additional reference words: FoxWin VFoxWin 2.50 2.50 2.50a 2.50b 2.60 2.60a
3.00
KBCategory: kbenv kbcode
KBSubcategory: FxprgFoxtools


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