PRB: PrivateProfile Problems, in 4.0b Macintosh Cross-Compiler (201597)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.0a
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, Macintosh Cross-Development Addon 4.0
- Microsoft Visual C++, Macintosh Cross-Development Addon 4.0b
This article was previously published under Q201597 SYMPTOMS
The PrivateProfile family of routines may fail on the Macintosh operating system due to caching of the preference file name.
CAUSE
The PrivateProfile family of routines supported on the Macintosh (GetPrivateProfileInt, GetPrivateProfileString, and WritePrivateProfileString) cache the previously opened preference file by file name. This preference file is closed on idle to avoid repeated opening and closing of preference files. This mechanism fails if an already opened file is specified later by a PrivateProfile routine using a different file name.
Consider the case where "test preferences" is passed to GetPrivateProfileString first and "Macintosh HD:System Folder:Preferences:test preferences" is subsequently passed to WritePrivateProfileString. While the second reference is valid and the correct file is found, the file name is not recognized as the same file name already cached. The second attempt to open the file fails. Specifically, an attempt to create the file fails with an unexpected error code (other than dupFNErr). When this happens, GetPrivateProfileString and GetPrivateProfileInt return the default value and WritePrivateProfileString fails.
RESOLUTION
To work around this problem, always specify the file in the same way.
Prior to calling InitInstance, the Microsoft Foundation Class (MFC) references a preference file with the same name as the application, with " Preferences" appended to it. It specifies the file by only the file name. If you need to access this same preference file from within InitInstance(), you must use only the file name.
Consider always using only the file name to reference any preference file that may also be referenced internally by the MFC.
Modification Type: | Major | Last Reviewed: | 12/8/2003 |
---|
Keywords: | kbNoUpdate kbprb kbRegistry KB201597 |
---|
|