c++windowswinapifunction

What is the purpose of GetPrivateProfileString?


I have come across the term GetPrivateProfileString in a C++ program. Could anyone give me a simple explanation of the use of this function?

The code on my page is:

GetPrivateProfileString("files", "directory", "/mediadb/files/", directory, os.path.getsize(directory), "apache")

Solution

  • 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.