Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of GetPrivateProfileString? [closed]

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")
like image 853
smurf Avatar asked Sep 07 '11 15:09

smurf


3 Answers

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.

like image 93
David Heffernan Avatar answered Nov 06 '22 06:11

David Heffernan


It's for reading from .ini files. It's an old win16 API. You shouldn't use it.

like image 25
i_am_jorf Avatar answered Nov 06 '22 08:11

i_am_jorf


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
);
like image 28
Macmade Avatar answered Nov 06 '22 07:11

Macmade