INI文件的读封装
2021-09-07
58
0
INI文件的读写类封装,可以自动创建INF文件。
简单地封装了获取inf文件相关节的内容。
ini.h
class CIni
{
public:
char m_fileName[512];
public:
CIni::CIni();
CIni(const char* filename);
virtual ~CIni();
UINT GetKeyUint(LPCTSTR section,LPCTSTR key);
void SetFileName(const char* filename);
DWORD GetKeyStr(LPCTSTR lpAppName,LPCTSTR lpKeyName, LPTSTR lpReturnedString);
};
ini.cpp
CIni::CIni()
{
}
CIni::CIni(const char* filename)
{
SetFileName(filename);
}
CIni::~CIni()
{
}
DWORD CIni::GetKeyStr(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPTSTR lpReturnedString)
{
return ::GetPrivateProfileString(lpAppName,lpKeyName,NULL,lpReturnedString,512,m_fileName);
}
void CIni::SetFileName(const char *filename)
{
memset(m_fileName,'\0',sizeof(m_fileName));
strcpy(m_fileName,filename);
}
UINT CIni::GetKeyUint(LPCTSTR section, LPCTSTR key)
{
return GetPrivateProfileInt(section,key,0,m_fileName);
}