BUG: GetPrivateProfileSection Opens INI File in Read/Write Mode (198906)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows 95
    • the operating system: Microsoft Windows 98
    • the operating system: Microsoft Windows Millennium Edition

This article was previously published under Q198906

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 that this is a bug in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:9/27/2004
Keywords:kbbug kbKernBase kbRegistry KB198906