19.1.1 Sharing Directories

Many applications store configuration files in the same directory as the executable file for the application. This method does not work for multiple users, however, because the application stores each user's information in the same directory, overwriting the other users' information in the process.

Instead of using configuration files, an application should use the Windows profile functions to store user-specific information in initialization (.INI) files. The profile functions create initialization files in a user's private Windows directory, unless the application specifies a different directory.

Windows profile functions, such as WriteProfileString, usually store profile and configuration information in .INI files. Profile functions fall into two categories: those that access WIN.INI and those that access another .INI file specified by the program.

The functions that access WIN.INI are GetProfileString, GetProfileInt, and WriteProfileString. Because each user has a unique copy of WIN.INI, these functions can be used safely, even when the application is being shared by more than one user.

The functions that access other .INI files are GetPrivateProfileString, GetPrivateProfileInt, and WritePrivateProfileString. These functions behave similarly to the functions that access WIN.INI, except that the application specifies the name of the private initialization file. When using these functions, you should specify the name of the file, but not a complete path (for example, MYAPP.INI instead of C:\MYAPP\MYAPP.INI). By default, the file will be located in the user's private Windows directory; specifying a full path could give multiple users access to the same file.

The exception to the preceding rule are initialization files that need to be shared
by all users. Make sure that those files cannot be left in an inconsistent state if
multiple users update them simultaneously.

For a full description of the profile functions, see the Microsoft Windows Programmer's Reference, Volume 2.