-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIniReader.cpp
More file actions
43 lines (42 loc) · 1.44 KB
/
IniReader.cpp
File metadata and controls
43 lines (42 loc) · 1.44 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
42
43
#include "IniReader.h"
#include <iostream>
#include <Windows.h>
IniReader::IniReader(char* szFileName)
{
memset(m_szFileName, 0x00, 255);
memcpy(m_szFileName, szFileName, strlen(szFileName));
}
int IniReader::ReadInteger(char* szSection, char* szKey, int iDefaultValue)
{
int iResult = GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
return iResult;
}
float IniReader::ReadFloat(char* szSection, char* szKey, float fltDefaultValue)
{
char szResult[255];
char szDefault[255];
float fltResult;
sprintf(szDefault, "%f",fltDefaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
fltResult = atof(szResult);
return fltResult;
}
bool IniReader::ReadBoolean(char* szSection, char* szKey, bool bolDefaultValue)
{
char szResult[255];
char szDefault[255];
bool bolResult;
sprintf(szDefault, "%s", bolDefaultValue? "True" : "False");
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
bolResult = (strcmp(szResult, "True") == 0 ||
strcmp(szResult, "true") == 0) ? true : false;
return bolResult;
}
char* IniReader::ReadString(char* szSection, char* szKey, const char* szDefaultValue)
{
char* szResult = new char[255];
memset(szResult, 0x00, 255);
GetPrivateProfileString(szSection, szKey,
szDefaultValue, szResult, 255, m_szFileName);
return szResult;
}