windows GetPrivateProfileString 的目的是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7336185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the purpose of GetPrivateProfileString?
提问by smurf
I have come across the term GetPrivateProfileString
in a C++ program. Could anyone give me a simple explanation of the use of this function?
我GetPrivateProfileString
在 C++ 程序中遇到过这个术语。谁能给我简单解释一下这个功能的使用?
The code on my page is:
我页面上的代码是:
GetPrivateProfileString("files", "directory", "/mediadb/files/", directory, os.path.getsize(directory), "apache")
回答by David Heffernan
GetPrivateProfileString()
reads values from .ini files.
GetPrivateProfileString()
从 .ini 文件中读取值。
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!
回到 16 位 Windows 时代,它是读取和写入应用程序配置数据的方式。当时,应用程序将其配置存储在系统目录中的共享 .ini 文件中,称为 win.ini。艰难时期!
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.
要从 win.ini 中读取,您调用了GetProfileString()
. private inGetPrivateProfileString()
表明这一奇妙的功能允许您访问 win.ini 以外的 .ini 文件,即您的应用程序的私有文件。如果我没记错的话(而且我的记忆是模糊的),大多数应用程序在 win.ini 被正式拒绝使用之后,多年来一直继续使用它。
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.
碰巧这GetPrivateProfileString()
是一个令人难以置信的皱纹野兽,具有可怕的性能特征和难以理解的奇怪之处。我个人像瘟疫一样避免它,如果我必须处理 .ini 文件,我会使用定制代码来执行此操作。
Raymond Chen has a nice articleabout why .ini files were deprecated in favour of the registry.
Raymond Chen 有一篇很好的文章,介绍了为什么不推荐使用 .ini 文件以支持注册表。
回答by Macmade
From MSDN:
来自 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.
从初始化文件中的指定部分检索字符串。
笔记
提供此功能只是为了与 16 位基于 Windows 的应用程序兼容。应用程序应在注册表中存储初始化信息。
Syntax
句法
DWORD WINAPI GetPrivateProfileString(
__in LPCTSTR lpAppName,
__in LPCTSTR lpKeyName,
__in LPCTSTR lpDefault,
__out LPTSTR lpReturnedString,
__in DWORD nSize,
__in LPCTSTR lpFileName
);
回答by antlersoft
This retrieves configuration information from an .ini file
这将从 .ini 文件中检索配置信息
回答by i_am_jorf
It's for readingfrom .ini files. It's an old win16 API. You shouldn't use it.