-
Notifications
You must be signed in to change notification settings - Fork 69
/
IniWriter.cpp
38 lines (32 loc) · 1.31 KB
/
IniWriter.cpp
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
#include "IniWriter.h"
#include <iostream>
#include <windows.h>
// http://blog.csdn.net/sdcxyz/article/details/10946111
// http://www.codeproject.com/Tips/376146/A-Small-Class-to-Read-INI-Files
CIniWriter::CIniWriter(LPCTSTR szFileName)
{
memset(m_szFileName, 0x00, sizeof(m_szFileName));
memcpy(m_szFileName, szFileName, _tcslen(szFileName)*sizeof(TCHAR));
}
void CIniWriter::WriteInteger(LPCTSTR szSection, LPCTSTR szKey, int iValue)
{
TCHAR szValue[255];
_sntprintf_s(szValue, sizeof(szValue) - 1, TEXT("%d"), iValue);
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CIniWriter::WriteFloat(LPCTSTR szSection, LPCTSTR szKey, float fltValue)
{
TCHAR szValue[255];
_sntprintf_s(szValue, sizeof(szValue) - 1, TEXT("%f"), fltValue);
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CIniWriter::WriteBoolean(LPCTSTR szSection, LPCTSTR szKey, bool bolValue)
{
TCHAR szValue[255];
_sntprintf_s(szValue, sizeof(szValue) - 1, TEXT("%s"), bolValue ? TEXT("True") : TEXT("False"));
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CIniWriter::WriteString(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szValue)
{
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}