设为首页 加入收藏

TOP

VC操作INI文件(二)
2014-11-23 17:59:48 来源: 作者: 【 】 浏览:18
Tags:操作 INI 文件
PCTSTR lpszKeyName, LPCTSTR lpszKeyValue); DWORD GetProfileSectionNames(CStringArray& strArray); // 返回section数量 int GetProfileInt(LPCTSTR lpszSectionName, LPCTSTR lpszKeyName); DWORD GetProfileString(LPCTSTR lpszSectionName, LPCTSTR lpszKeyName, CString& szKeyValue); BOOL DeleteSection(LPCTSTR lpszSectionName); BOOL DeleteKey(LPCTSTR lpszSectionName, LPCTSTR lpszKeyName); private: CString m_szFileName; // .//Config.ini, 如果该文件不存在,则exe第一次试图Write时将创建该文件 UINT m_unMaxSection; // 最多支持的section数(256) UINT m_unSectionNameMaxSize; // section名称长度,这里设为32(Null-terminated) void Init(); }; #endif // IniFile.cpp #include "IniFile.h" void CIniFile::Init() { m_unMaxSection = 512; m_unSectionNameMaxSize = 33; // 32位UID串 } CIniFile::CIniFile() { Init(); } CIniFile::CIniFile(LPCTSTR szFileName) { // (1) 绝对路径,需检验路径是否存在 // (2) 以"./"开头,则需检验后续路径是否存在 // (3) 以"../"开头,则涉及相对路径的解析 Init(); // 相对路径 m_szFileName.Format(".//%s", szFileName); } CIniFile::~CIniFile() { } void CIniFile::SetFileName(LPCTSTR szFileName) { m_szFileName.Format(".//%s", szFileName); } DWORD CIniFile::GetProfileSectionNames(CStringArray &strArray) { int nAllSectionNamesMaxSize = m_unMaxSection*m_unSectionNameMaxSize+1; char *pszSectionNames = new char[nAllSectionNamesMaxSize]; DWORD dwCopied = 0; dwCopied = ::GetPrivateProfileSectionNames(pszSectionNames, nAllSectionNamesMaxSize, m_szFileName); strArray.RemoveAll(); char *pSection = pszSectionNames; do { CString szSection(pSection); if (szSection.GetLength() < 1) { delete[] pszSectionNames; return dwCopied; } strArray.Add(szSection); pSection = pSection + szSection.GetLength() + 1; // next section name } while (pSection && pSection
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[VC++]009菜单命令响应函数 下一篇VC 枚举进程

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: