\t\t孙鑫 第十二课之四 WriteProfileString / GetProfileString用法
2012-12-05 17:19
399 查看
1 说明
WriteProfileString / GetProfileString一种是WIN32 API,另一种是CWinApp的成员函数,因此要分清楚。
WIN32 API的功能是写入win.ini文件,CWinApp成员函数的功能根据OS不同而不同,一般是写入注册表,WIN NT写入注册表,WIN 3.X写入win.ini。 WIN7也是写入注册表。
2 WIN32 API
①写入win.ini配置文件
BOOL WriteProfileString(
LPCTSTR lpAppName,// 段名 sectio name
LPCTSTR lpKeyName,// 键名 key name
LPCTSTR lpString// 键值 string to write
);
WIN32 API函数的功能是把上述三个参数写如win.ini文件,该文件在windows7下的位置是X:\windows\win.ini。
eg.
//写win.ini文件
::WriteProfileString("SectionName", "KeyName", "ValueofKey");
写完后效果如下图:
②从win.ini文件中读取指定段和键的值
DWORD GetProfileString(
LPCTSTR lpAppName,// 段名 section name
LPCTSTR lpKeyName,// 键名 key name
LPCTSTR lpDefault,// 默认字符串,当指定的段名或键名不存在的情况下把该字符串拷贝至第四个参数 。 default string
LPTSTRlpReturnedString,// 读到的键值存在该字符串指针中,如果不能取到则为第三个参数的值。destination buffer
DWORD nSize// buffer大小。 size of destination buffer
);
eg.
//从win.ini中读出写入的值
CString str;
::GetProfileString("SectionName", "KeyName", "defaultName", str.GetBuffer(100), 100);
执行后,str=="ValueofKey", 如果SectionName 或 KeyName不存在则str=="defaultName" 。
3 CWinApp成员函数
一般写入注册表,根据OS内核分。
①写入
BOOL WriteProfileString(
LPCTSTR lpszSection, //段名,对应注册表中目录
LPCTSTR lpszEntry, //入口,对应注册表中的"名称"
LPCTSTR lpszValue //键值,对应注册表中的"数据"
);
eg.
WriteProfileString("SectionName", "EntryName", "value");
效果如下:
②读出指定段名,指定入口的值
CString GetProfileString(
LPCTSTR lpszSection,//段名
LPCTSTR lpszEntry, //入口名
LPCTSTR lpszDefault=NULL //默认值,如果段名或入口不存在则返回该值
);
eg.
CString str;
str = GetProfileString("SectionName", "EntryName", "defaultValue");
执行后str == "value", 否则str=="defaultValue" 。
?
WriteProfileString / GetProfileString一种是WIN32 API,另一种是CWinApp的成员函数,因此要分清楚。
WIN32 API的功能是写入win.ini文件,CWinApp成员函数的功能根据OS不同而不同,一般是写入注册表,WIN NT写入注册表,WIN 3.X写入win.ini。 WIN7也是写入注册表。
2 WIN32 API
①写入win.ini配置文件
BOOL WriteProfileString(
LPCTSTR lpAppName,// 段名 sectio name
LPCTSTR lpKeyName,// 键名 key name
LPCTSTR lpString// 键值 string to write
);
WIN32 API函数的功能是把上述三个参数写如win.ini文件,该文件在windows7下的位置是X:\windows\win.ini。
eg.
//写win.ini文件
::WriteProfileString("SectionName", "KeyName", "ValueofKey");
写完后效果如下图:
②从win.ini文件中读取指定段和键的值
DWORD GetProfileString(
LPCTSTR lpAppName,// 段名 section name
LPCTSTR lpKeyName,// 键名 key name
LPCTSTR lpDefault,// 默认字符串,当指定的段名或键名不存在的情况下把该字符串拷贝至第四个参数 。 default string
LPTSTRlpReturnedString,// 读到的键值存在该字符串指针中,如果不能取到则为第三个参数的值。destination buffer
DWORD nSize// buffer大小。 size of destination buffer
);
eg.
//从win.ini中读出写入的值
CString str;
::GetProfileString("SectionName", "KeyName", "defaultName", str.GetBuffer(100), 100);
执行后,str=="ValueofKey", 如果SectionName 或 KeyName不存在则str=="defaultName" 。
3 CWinApp成员函数
一般写入注册表,根据OS内核分。
①写入
BOOL WriteProfileString(
LPCTSTR lpszSection, //段名,对应注册表中目录
LPCTSTR lpszEntry, //入口,对应注册表中的"名称"
LPCTSTR lpszValue //键值,对应注册表中的"数据"
);
eg.
WriteProfileString("SectionName", "EntryName", "value");
效果如下:
②读出指定段名,指定入口的值
CString GetProfileString(
LPCTSTR lpszSection,//段名
LPCTSTR lpszEntry, //入口名
LPCTSTR lpszDefault=NULL //默认值,如果段名或入口不存在则返回该值
);
eg.
CString str;
str = GetProfileString("SectionName", "EntryName", "defaultValue");
执行后str == "value", 否则str=="defaultValue" 。
?
相关文章推荐
- WritePrivateProfileString与GetPrivateProfileString用法与区别
- 孙鑫 第十二课之四 WriteProfileString / GetProfileString用法
- 今日学习笔记:c# extern 关键字 和 kernel32.dll中的api:WritePrivateProfileString,GetPrivateProfileString
- WinAPI: WritePrivateProfileString、GetPrivateProfileString - 简单读写 Ini 文件
- INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
- C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()
- C 语言实现读配置文件(.ini)函数,替代GetPrivateProfileString,WritePrivateProfileString
- INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
- C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()
- 【转】INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
- INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
- MFC读写ini配置文件(WritePrivateProfileString,GetPrivateProfileString,GetPrivateProfileInt)
- C#操作INI文件(调用WindowsAPI函数:WritePrivateProfileString,GetPrivateProfileString)
- GetPrivateProfileString ,WritePrivateProfileString详解
- 利用WritePrivateProfileString和GetPrivateProfileString读写配置文件.ini
- 写入配置的函数WritePrivateProfileString和读取配置文件的函数GetPrivateProfileInt和GetPrivateProfileString
- INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
- c++ stl实现对配置文件的读写 根据windows API WritePrivateProfileString,GetPrivateProfileString简单改写
- *.ini 文件 与 WritePrivateProfileString()和GetPrivateProfileString()
- INI文件编程中WINAPI函数WritePrivateProfileString,GetPrivateProfileString