开发者

What is the purpose of GetPrivateProfileString? [closed]

This question is unlikely to help any future visitors; it is only relevan开发者_Python百科t to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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")


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.


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


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
);


This retrieves configuration information from an .ini file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜