CWinApp::GetProfileString
CString GetProfileString( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL );
返回值
返回值是应用程序的.INI文件中的字符串,如果找不到该字符串,则为lpszDefault。框架支持的字符串最大长度为_MAX_PATH。如果lpszDefault为NULL,则返回值是一个空字符串。
参数:
lpszSection
指向一个以null结尾的字符串,指定了包含入口的部分。
lpszEntry
指向一个以null结尾的字符串,其中包含了要获取字符串的入口。这个值不能为NULL。
lpszDefault
指向给定入口的缺省字符串值,当初始化文件中找不到入口时使用该值。
说明:
调用这个函数以获得与应用程序的注册表或.INI文件中指定部分的入口相关的字符串。
这些入口按照如下方式保存:
·Windows NT 该值保存在注册表中
·Windows 3.X 该值保存在WIN.INI文件中
·Windows 95 该值保存在WIN.INI的缓冲版本中
示例:
CString strSection = "My Section";
CString strStringItem = "My String Item";
CString strIntItem = "My Int Item";
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileString(strSection, strStringItem, "test");
CString strValue;
strValue = pApp->GetProfileString(strSection, strStringItem);
ASSERT(strValue == "test");
pApp->WriteProfileInt(strSection, strIntItem, 1234);
int nValue;
nValue = pApp->GetProfileInt(strSection, strIntItem, 0);
ASSERT(nValue == 1234);
请参阅:
CWinApp::GetProfileInt
,
CWinApp::WriteProfileString
, ::GetPrivateProfileString