-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathIniReader.cpp
More file actions
41 lines (40 loc) · 1.46 KB
/
Copy pathIniReader.cpp
File metadata and controls
41 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "stdafx.h"
#include "IniReader.h"
CIniReader::CIniReader(LPCTSTR szFileName)
{
memset(m_szFileName, 0x00, sizeof(m_szFileName));
memcpy(m_szFileName, szFileName, _tcslen(szFileName) * sizeof(TCHAR));
}
int CIniReader::ReadInteger(LPCTSTR szSection, LPCTSTR szKey, int iDefaultValue)
{
int iResult = GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
return iResult;
}
float CIniReader::ReadFloat(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR format, float fltDefaultValue)
{
TCHAR szResult[255];
TCHAR szDefault[255];
float fltResult;
_stprintf_s(szDefault, 255, format, fltDefaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
fltResult = (float)_tstof(szResult);
return fltResult;
}
bool CIniReader::ReadBoolean(LPCTSTR szSection, LPCTSTR szKey, bool bolDefaultValue)
{
TCHAR szResult[255];
TCHAR szDefault[255];
bool bolResult;
_stprintf_s(szDefault, 255, TEXT("%s"), bolDefaultValue ? TEXT("True") : TEXT("False"));
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
bolResult = (_tcscmp(szResult, TEXT("True")) == 0 ||
_tcscmp(szResult, TEXT("true")) == 0) ? true : false;
return bolResult;
}
LPTSTR CIniReader::ReadString(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szDefaultValue)
{
LPTSTR szResult = new TCHAR[255];
memset(szResult, 0x00, sizeof(szResult));
GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, m_szFileName);
return szResult;
}