c++ – What is the purpose of GetPrivateProfileString?

c++ – What is the purpose of GetPrivateProfileString?

GetPrivateProfileString() reads values from .ini files.

Way back when, in the days of 16-bit Windows, it was the way to read and write application configuration data. Back then applications stored their configuration in a shared .ini file that lived in the system directory, called win.ini. Bad times!

To read from win.ini you called GetProfileString(). The private in GetPrivateProfileString() is indicative of the fact that this wonderful function allowed you to access an .ini file other than win.ini, i.e. one private to your application. If I recall correctly (and my memory is hazy), most applications carried on using win.ini for years and years after it was officially frowned upon to do so.

It so happens that GetPrivateProfileString() is an incredibly wrinkly beast with terrible performance characteristics and hard to understand oddities. I personally avoid it like the plague and if I have to process .ini files I use bespoke code to do so.

Raymond Chen has a nice article about why .ini files were deprecated in favour of the registry.

From MSDN:

Retrieves a string from the specified section in an initialization
file.

Note

This function is provided only for compatibility with 16-bit
Windows-based applications. Applications should store initialization
information in the registry.

Syntax

DWORD WINAPI GetPrivateProfileString(
  __in   LPCTSTR lpAppName,
  __in   LPCTSTR lpKeyName,
  __in   LPCTSTR lpDefault,
  __out  LPTSTR lpReturnedString,
  __in   DWORD nSize,
  __in   LPCTSTR lpFileName
);

c++ – What is the purpose of GetPrivateProfileString?

This retrieves configuration information from an .ini file

Leave a Reply

Your email address will not be published.