Article ID: 95720 - View products that this article applies to.
This article was previously published under Q95720
This article has been archived. It is offered "as is" and will no longer be updated.
The following examples show how to write specific information to Windows- style .INI files. The first example shows how to write information to the WIN.INI file, and the second example shows how to write information to any other Windows-style .INI file.
Example 1The following code will write to the Load= line in the [Windows] section of the WIN.INI file:
MAPPNAME points to an application heading in the WIN.INI file. In this case, it is pointing to the [Windows] application name.
MKEYNAME points to a key name that appears under the application name. The above example points to the Load= line.
MSETTING is the string that contains the value to be assigned to the key name.
NOTE: The code in Example 1 puts CLOCK.EXE on the Load= line. It does not append CLOCK.EXE to any existing information for this key name. It simply replaces the value. If the Load= line was not present in the [Windows] section of the WIN.INI file, this code would have added it.
MREGISTER is the variable name that defines the function using the RegFn function. The sample code above registers the function WriteProfileString and will write information to the WIN.INI file.
MCALL is used to call the function defined in MREGISTER and pass it the appropriate parameters.
To write to a different section of the WIN.INI, change the value of MAPPNAME to the appropriate application name. Also, change the MKEYNAME value to the key name that will hold the information, and change the MSETTING value to the setting to store in the selected key name.
NOTE: The application name and key name are not case sensitive.
Example 2The following code will change the COLOR SCHEMES= line in the [Current] section of the CONTROL.INI file:
The commands are almost the same as those in Example 1, except that Example 2 uses WritePrivateProfileString. This allows you to specify a Windows- style .INI file other than the WIN.INI file. One other difference is the addition of MFILENAME to specify the .INI file to write to. By default, if no path is specified, Windows will look in the Windows program directory for the .INI file.