BUG: GetPrivateProfileSection Opens INI File in Read/Write Mode

ID: Q198906


The information in this article applies to:


SYMPTOMS

GetPrivateProfileSection sometimes returns 0, even though the specified section is contained in the initialization file.


CAUSE

The GetPrivateProfileSection API opens the initialization file with read and write access. If the initialization file is read only, this function returns 0.


RESOLUTION

You can resolve this error by making a call to GetPrivateProfileString before GetPrivateProfileSection. Make the GetPrivateProfileString call as follows before calling any other profile functions:


char buffer[4096];

GetPrivateProfileString(NULL, NULL, NULL,
            buffer, sizeof(buffer), "ABC.INI"); 
The profile functions are provided for compatibility with 16-bit applications written for Windows. It is recommended that all Win32-based applications store initialization information in the registry and use the Win32 registry APIs to retrieve these values.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Additional query words:


Keywords          : kbKernBase kbRegistry kbWinOS95 kbWinOS98 
Version           : winnt:
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: March 10, 1999