123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //***********************************************************************
- // (c) xqsoft,版权所有不得拷贝(2003)
- // IniFile.cpp
- // 功能:修改后的INI文件类,支持读写删除。
- // 记录到INI格式文件
- //***********************************************************************
- #include "stdafx.h"
- #include "IniFile.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- /////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- /////////////////////////////////////////////////////////////////////
- //default constructor
- CIniFile::CIniFile()
- {
- GetModuleFileName(NULL,m_szFilePath,5000/*MAX_PATH*/);
- int iLen = _tcslen(m_szFilePath);
- m_szFilePath[iLen-1]=_T('i');
- m_szFilePath[iLen-2]=_T('n');
- m_szFilePath[iLen-3]=_T('i');
-
- }
- //default destructor
- CIniFile::~CIniFile()
- {
- }
- //sets path of ini file to read and write from
- void CIniFile::SetPath(LPCTSTR szPath)
- {
- _stprintf(m_szFilePath,_T("%s"),szPath);
- }
- BOOL CIniFile::GetVarStr(LPCTSTR strSection,LPCTSTR strVarName,CString & strValue)
- {
- TCHAR strReturnValue[5000/*MAX_PATH*/];
- DWORD dr = GetPrivateProfileString(strSection,strVarName,NULL,strReturnValue,5000/*MAX_PATH*/,m_szFilePath);
- strValue = strReturnValue;
- if(dr == NULL)return FALSE;
- return TRUE;
- }
- BOOL CIniFile::GetVarStr(LPCTSTR strSection,LPCTSTR strVarName,LPTSTR strReturnValue)
- {
- DWORD dr = GetPrivateProfileString(strSection,strVarName,NULL,strReturnValue,5000/*MAX_PATH*/,m_szFilePath);
- if(dr == NULL)return FALSE;
- return TRUE;
- }
- BOOL CIniFile::GetVarInt(LPCTSTR strSection,LPCTSTR strVarName,int & iValue)
- {
- DWORD dr;
- TCHAR strReturnValue[5000/*MAX_PATH*/];
- dr = GetPrivateProfileString(strSection,strVarName,NULL,strReturnValue,5000/*MAX_PATH*/,m_szFilePath);
- #if _UNICODE
- iValue = _wtoi(strReturnValue);
- #else
- iValue = atoi(strReturnValue);
- #endif
- if(dr == NULL)return FALSE;
- return TRUE;
- }
- BOOL CIniFile::SetVarStr(LPCTSTR strSection,LPCTSTR strVarName,LPCTSTR strValue)
- {
- DWORD dr = WritePrivateProfileString(strSection,strVarName,strValue,m_szFilePath);
- if(dr == NULL)return FALSE;
- return TRUE;
- }
- BOOL CIniFile::SetVarInt(LPCTSTR strSection,LPCTSTR strVarName,const int iValue)
- {
- TCHAR strValue[5000/*MAX_PATH*/];
- _stprintf(strValue,_T("%d"),iValue);
- DWORD dr = WritePrivateProfileString(strSection,strVarName,strValue,m_szFilePath);
- if(dr == NULL)return FALSE;
- return TRUE;
- }
|