-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIni.cpp
More file actions
76 lines (59 loc) · 1.7 KB
/
Ini.cpp
File metadata and controls
76 lines (59 loc) · 1.7 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Ini.cpp: implementation of the CIni class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Ini.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIni::CIni()
{
}
CIni::~CIni()
{
}
DWORD CIni::ReadString(LPCTSTR lpAppName, LPCTSTR lpKyeValue, LPTSTR lpReturnStr,
DWORD nSize, LPCTSTR lpFileName, LPCTSTR lpDefault/* = NULL*/)
{
TCHAR FilePath[255] = {".\\"};
lstrcat(FilePath, lpFileName);
return GetPrivateProfileString(lpAppName, lpKyeValue, lpDefault,
lpReturnStr, nSize, FilePath);
}
BOOL CIni::WriteString(LPCTSTR lpAppName, LPCTSTR lpKeyValue, LPCTSTR lpStr,
LPCTSTR lpFileName)
{
TCHAR FilePath[255] = {".\\"};
lstrcat(FilePath, lpFileName);
return WritePrivateProfileString(lpAppName, lpKeyValue, lpStr,
FilePath);
}
int CIni::GetSections(CStringArray& arrSection, LPCTSTR lpFileName)
{
TCHAR FilePath[255] = {".\\"};
lstrcat(FilePath, lpFileName);
TCHAR szSectionNames[2048] = {'\0'};
char* pszSectionName = NULL;
int j = 0;
int count = 0;
GetPrivateProfileSectionNames(szSectionNames, 2048, FilePath);
for (int i=0; i<2048; ++i, j++)
{
if (szSectionNames[0] == '\0') break;
if (szSectionNames[i] == '\0')
{
pszSectionName = &szSectionNames[i - j];
j = -1;
CString strAppName = pszSectionName;
arrSection.Add(strAppName);
count++;
if (szSectionNames[i+1] == '\0') break;
}
}
return count;
}