-
Notifications
You must be signed in to change notification settings - Fork 8
/
IniFile.cpp
697 lines (669 loc) · 18.7 KB
/
IniFile.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
// IniFile.cpp: implementation of the IniFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IniFile.h"
#include "resource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CString IniFile::g_basePath;
#define INIFILE_MAGIC 'INIB'
#define INIFILE_VERSION 1
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IniFile::IniFile(const CString &path)
{
m_path = path;
if (path.Left(4) == "res\\")
{
GetResource();
CHECKERR((m_hFile = CreateFile(g_basePath + "tempFLC.ini", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL)) != INVALID_HANDLE_VALUE);
}
else
{
CString fullpath = PathIsRelative(path) ? g_basePath + path : path;
if (!PathFileExists(fullpath))
FatalError(L"File " + path + L" not found");
CHECKERR((m_hFile = CreateFile(fullpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE);
}
DWORD size = GetFileSize(m_hFile, NULL);
if (size == 0)
{
m_hFileMappingObject = INVALID_HANDLE_VALUE;
m_textMode = false;
m_firstSection = NULL;
m_stringtable = NULL;
}
else
{
CHECKERR((m_hFileMappingObject = CreateFileMapping(m_hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL);
CHECKERR((m_baseAddress = reinterpret_cast<LPSTR>(MapViewOfFile(m_hFileMappingObject, FILE_MAP_READ, 0, 0, 0))) != NULL);
m_endAddress = m_baseAddress+size;
struct IniHeader
{
DWORD magic; // "BINI"
DWORD version; // 1
DWORD stringtableOffset;
} *header = reinterpret_cast<IniHeader*>(m_baseAddress);
m_textMode = (header->magic != INIFILE_MAGIC);
if (!m_textMode)
{
if (header->version != INIFILE_VERSION)
ProblemFound(L"%s: Unexpected BINI header version (%d)", path, header->version);
m_stringtable = m_baseAddress+header->stringtableOffset;
m_firstSection = reinterpret_cast<LPWORD>(header+1);
}
}
}
IniFile::~IniFile()
{
if (m_hFileMappingObject != INVALID_HANDLE_VALUE)
{
CHECKERR(UnmapViewOfFile(m_baseAddress));
CHECKERR(CloseHandle(m_hFileMappingObject));
}
CHECKERR(CloseHandle(m_hFile));
}
IniSection IniFile::FindFirstSection(LPCSTR sectionName)
{
// TODO: optimiser eventuellement
IniSection section = NULL;
CString name;
while (GetNextSection(section, name))
if (name == sectionName)
return m_curSection = section;
return m_curSection = NULL;
}
CString IniFile::GetCurrentSectionName()
{
if (m_textMode)
{
LPSTR scanEnd = reinterpret_cast<LPSTR>(m_curSection);
while (*--scanEnd != ']');
LPSTR scan = scanEnd;
while (*--scan != '[');
return CString(scan+1, scanEnd-scan-1);
}
else
return m_stringtable+*m_curSection;
}
BOOL IniFile::GetNextSection(IniSection §ion, CString &name)
{
if (m_textMode)
{
LPSTR sectionStart = (section == NULL) ? m_baseAddress : reinterpret_cast<LPSTR>(section);
LPSTR sectionHead;
do
{
sectionHead = sectionStart;
sectionStart = reinterpret_cast<LPSTR>(memchr(sectionHead,'\n', m_endAddress-sectionHead));
if (sectionStart)
sectionStart++;
else
return false;
} while (*sectionHead != '[');
name = CString(sectionHead+1, strchr(sectionHead, ']')-sectionHead-1);
m_curSection = section = (IniSection) sectionStart;
return true;
}
else
{
if (section == NULL)
section = m_firstSection;
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
section++;
BYTE valuesCount = *reinterpret_cast<const BYTE*>(section);
reinterpret_cast<BYTE*&>(section) += 1+valuesCount*5;
entriesCount--;
}
}
if (section == reinterpret_cast<IniSection>(m_stringtable))
{
section = NULL;
return false;
}
m_curSection = section;
name = m_stringtable+*section;
}
return true;
}
CString IniFile::GetValue(IniSection section, LPCSTR valueName)
{
if (m_textMode)
{
size_t nameLen = strlen(valueName);
LPCSTR scan = reinterpret_cast<LPCSTR>(section);
LPCSTR lineEnd;
do
{
if (*scan == '[') break;
lineEnd = reinterpret_cast<LPCSTR>(memchr(scan, '\n', m_endAddress-scan));
if (lineEnd == NULL) lineEnd = m_endAddress;
if (memicmp(scan, valueName, nameLen) == 0)
{
scan += nameLen;
while ((*scan == ' ') || (*scan == '\t')) scan++;
if (*scan++ == '=')
{
while ((*scan == ' ') || (*scan == '\t')) scan++;
if (scan < lineEnd)
{
LPCSTR comment = reinterpret_cast<LPCSTR>(memchr(scan, ';', lineEnd-scan));
if (comment)
lineEnd = comment;
while (isspace(lineEnd[-1])) lineEnd--;
if (scan < lineEnd)
return CString(scan, lineEnd-scan);
else
return CString();
}
}
}
scan = lineEnd+1;
} while (lineEnd < m_endAddress);
}
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*section++;
BYTE valuesCount = *reinterpret_cast<LPBYTE>(section);
if (stricmp(valueName, name) == 0)
{
if (valuesCount != 1)
ProblemFound(L"%s: [%s] %s has a %hs= with %d values instead of 1 expected", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName, valuesCount);
CHECK(reinterpret_cast<LPBYTE>(section)[1] == 3);
return m_stringtable+*reinterpret_cast<LPDWORD>(section+1);
}
reinterpret_cast<LPBYTE&>(section) += 1+valuesCount*5;
entriesCount--;
}
}
ProblemFound(L"%s: [%s] %s is missing a %hs=", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName);
return CString();
}
int IniFile::GetValueInt(IniSection section, LPCSTR valueName)
{
if (m_textMode)
return _ttoi(GetValue(section, valueName));
else
{
LPWORD scan = section+1;
WORD entriesCount = *scan++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*scan++;
BYTE valuesCount = *reinterpret_cast<LPBYTE>(scan);
if (stricmp(valueName, name) == 0)
{
if (valuesCount != 1)
ProblemFound(L"%s: [%s] %s has a %hs= with %d values instead of 1 expected", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName, valuesCount);
CHECK(reinterpret_cast<LPBYTE>(scan)[1] == 1);
return *reinterpret_cast<LPDWORD>(scan+1);
}
reinterpret_cast<LPBYTE&>(scan) += 1+valuesCount*5;
entriesCount--;
}
}
ProblemFound(L"%s: [%s] %s is missing a %hs=", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName);
return 0;
}
float IniFile::GetValueFloat(IniSection section, LPCSTR valueName)
{
if (m_textMode)
return (float) _tcstod(GetValue(section, valueName), NULL);
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*section++;
BYTE valuesCount = *reinterpret_cast<LPBYTE&>(section)++;
if (stricmp(valueName, name) == 0)
{
if (valuesCount != 1)
ProblemFound(L"%s: [%s] %s has a %hs= with %d values instead of 1 expected", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName, valuesCount);
IniValue *value = reinterpret_cast<IniValue*>(section);
if (value->type == IniValue::vtFloat)
return value->vFloat;
else if (value->type == IniValue::vtInt)
return (float) value->vInt;
else
{
BadType(value, 0, L"float");
if (value->type == IniValue::vtString)
return (float) strtod(m_stringtable+value->vInt, NULL);
else
return 0.0;
}
}
reinterpret_cast<LPBYTE&>(section) += valuesCount*5;
entriesCount--;
}
}
ProblemFound(L"%s: [%s] %s is missing a %hs=", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName);
return 0;
}
CString IniFile::GetValue0(IniSection section, LPCSTR valueName) // same as GetValue but does not break if missing
{
if (m_textMode)
{
size_t nameLen = strlen(valueName);
LPCSTR scan = reinterpret_cast<LPCSTR>(section);
LPCSTR lineEnd;
do
{
if (*scan == '[') break;
lineEnd = reinterpret_cast<LPCSTR>(memchr(scan, '\n', m_endAddress-scan));
if (lineEnd == NULL) lineEnd = m_endAddress;
if (memicmp(scan, valueName, nameLen) == 0)
{
scan += nameLen;
while ((*scan == ' ') || (*scan == '\t')) scan++;
if (*scan++ == '=')
{
while ((*scan == ' ') || (*scan == '\t')) scan++;
if (scan < lineEnd)
{
LPCSTR comment = reinterpret_cast<LPCSTR>(memchr(scan, ';', lineEnd-scan));
if (comment)
lineEnd = comment;
while (isspace(lineEnd[-1])) lineEnd--;
if (scan < lineEnd)
return CString(scan, lineEnd-scan);
else
return CString();
}
}
}
scan = lineEnd+1;
} while (lineEnd < m_endAddress);
}
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*section++;
BYTE valuesCount = *reinterpret_cast<LPBYTE>(section);
if (stricmp(valueName, name) == 0)
{
if (valuesCount != 1)
ProblemFound(L"%s: [%s] %s has a %hs= with %d values instead of 1 expected", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName, valuesCount);
CHECK(reinterpret_cast<LPBYTE>(section)[1] == 3);
return m_stringtable+*reinterpret_cast<LPDWORD>(section+1);
}
reinterpret_cast<LPBYTE&>(section) += 1+valuesCount*5;
entriesCount--;
}
}
return CString();
}
int IniFile::GetValueInt0(IniSection section, LPCSTR valueName) // same as GetValueInt but does not break if missing
{
if (m_textMode)
return _ttoi(GetValue0(section, valueName));
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*section++;
BYTE valuesCount = *reinterpret_cast<LPBYTE>(section);
if (stricmp(valueName, name) == 0)
{
if (valuesCount != 1)
ProblemFound(L"%s: [%s] %s has a %hs= with %d values instead of 1 expected", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName, valuesCount);
CHECK(reinterpret_cast<LPBYTE>(section)[1] == 1);
return *reinterpret_cast<LPDWORD>(section+1);
}
reinterpret_cast<LPBYTE&>(section) += 1+valuesCount*5;
entriesCount--;
}
}
return 0;
}
float IniFile::GetValueFloat0(IniSection section, LPCSTR valueName)
{
if (m_textMode)
return (float) _tcstod(GetValue0(section, valueName), NULL);
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*section++;
BYTE valuesCount = *reinterpret_cast<LPBYTE&>(section)++;
if (stricmp(valueName, name) == 0)
{
if (valuesCount != 1)
ProblemFound(L"%s: [%s] %s has a %hs= with %d values instead of 1 expected", m_path, GetCurrentSectionName(), GetValue0(section, "nickname"), valueName, valuesCount);
IniValue *value = reinterpret_cast<IniValue*>(section);
if (value->type == IniValue::vtFloat)
return value->vFloat;
else if (value->type == IniValue::vtInt)
return (float) value->vInt;
else
{ // rare case of a string
CHECK(value->type == IniValue::vtString);
return (float) strtod(m_stringtable+value->vInt, NULL);
}
}
reinterpret_cast<LPBYTE&>(section) += valuesCount*5;
entriesCount--;
}
}
return 0;
}
UINT IniFile::GetValues(IniSection section, LPCSTR valueName, IniValue *&values)
{
values = NULL;
m_curEntry = valueName;
if (m_textMode)
{
size_t nameLen = strlen(valueName);
LPSTR scan = reinterpret_cast<LPSTR>(section);
LPSTR lineEnd;
do
{
if (*scan == '[') break;
lineEnd = reinterpret_cast<LPSTR>(memchr(scan, '\n', m_endAddress-scan));
if (lineEnd == NULL) lineEnd = m_endAddress;
if (memicmp(scan, valueName, nameLen) == 0)
{
scan += nameLen;
scan += strspn(scan, " \t");
if (*scan++ == '=')
{
scan += strspn(scan, " \t");
values = reinterpret_cast<IniValue*>(scan);
UINT valuesCount = 1;
while (scan = reinterpret_cast<LPSTR>(memchr(scan, ',', lineEnd-scan)))
valuesCount++, scan++;
return valuesCount;
}
}
scan = lineEnd+1;
} while (lineEnd < m_endAddress);
}
else
{
section++;
WORD entriesCount = *section++;
while (entriesCount)
{
LPCSTR name = m_stringtable+*section++;
BYTE valuesCount = *reinterpret_cast<LPBYTE&>(section)++;
if (stricmp(valueName, name) == 0)
{
CHECK(valuesCount > 0);
values = reinterpret_cast<IniValue*>(section);
return valuesCount;
}
reinterpret_cast<LPBYTE&>(section) += valuesCount*5;
entriesCount--;
}
}
return 0;
}
CString IniFile::GetValueName(IniValue* value)
{
if (m_textMode)
{
LPCSTR scan = reinterpret_cast<LPCSTR>(value);
while (*--scan != '=');
while (isspace(*--scan));
LPCSTR scanEnd = scan+1;
while (*--scan != '\n');
while (isspace(*++scan));
return CString(scan, scanEnd-scan);
}
else
return m_stringtable+*reinterpret_cast<LPWORD>(reinterpret_cast<LPBYTE>(value)-3);
}
UINT IniFile::EnumEntries(IniSection section, IniEntry &entry)
{
if (m_textMode)
{
entry = section;
LPCSTR scan = reinterpret_cast<LPCSTR>(section);
UINT count = 0;
while ((*scan != '[') && (scan < m_endAddress))
{
while ((*scan == ' ') || (*scan == '\t')) scan++;
if ((*scan != '\r') && (*scan != '\n') && (*scan != ';'))
count++;
scan = reinterpret_cast<LPCSTR>(memchr(scan, '\n', m_endAddress-scan));
if (!scan) break;
scan++;
}
return count;
}
else
{
entry = section+2;
return section[1];
}
}
CString IniFile::GetNextEntry(IniEntry &entry, UINT &valuesCount, IniValue *&values)
{
if (m_textMode)
{
LPSTR scan = reinterpret_cast<LPSTR>(entry);
LPSTR lineEnd;
while (*scan != '[')
{
CHECK(scan < m_endAddress);
lineEnd = reinterpret_cast<LPSTR>(memchr(scan, '\n', m_endAddress-scan));
if (lineEnd == NULL) lineEnd = m_endAddress;
while ((*scan == ' ') || (*scan == '\t')) scan++;
if ((*scan != '\r') && (*scan != '\n') && (*scan != ';'))
{
entry = reinterpret_cast<IniEntry>(lineEnd+1);
while (isspace(lineEnd[-1])) lineEnd--;
LPSTR scan2 = reinterpret_cast<LPSTR>(memchr(scan, '=', lineEnd-scan));
if (scan2 == NULL)
{
values = NULL;
valuesCount = 0;
return m_curEntry = CString(scan, lineEnd-scan);
}
else
scan2++;
CString name = m_curEntry = CString(scan, scan2-scan-1);
name.TrimRight();
scan2 += strspn(scan2, " \t");
values = reinterpret_cast<IniValue*>(scan2);
if (lineEnd < scan2)
valuesCount = 0;
else
{
valuesCount = 1;
while (scan2 = reinterpret_cast<LPSTR>(memchr(scan2, ',', lineEnd-scan2)))
valuesCount++, scan2++;
}
return name;
}
else
scan = lineEnd+1;
}
return CString();
}
else
{
CString name = m_curEntry = m_stringtable+*entry++;
valuesCount = *reinterpret_cast<LPBYTE&>(entry)++;
values = reinterpret_cast<IniValue*>(entry);
entry = reinterpret_cast<IniEntry>(values+valuesCount);
return name;
}
}
CString IniFile::GetValue(IniValue *value, UINT indice)
{
if (m_textMode)
{
LPSTR scan = reinterpret_cast<LPSTR>(value);
while (indice)
{
indice--;
scan = strchr(scan,',')+1;
scan += strspn(scan, " \t");
}
LPSTR lineEnd = reinterpret_cast<LPSTR>(memchr(scan, '\n', m_endAddress-scan));
if (lineEnd == NULL) lineEnd = m_endAddress;
while (isspace(lineEnd[-1])) lineEnd--;
LPSTR scan2 = reinterpret_cast<LPSTR>(memchr(scan, ',', lineEnd-scan));
if (scan2 > scan) while (isspace(scan2[-1])) scan2--;
CString val = CString(scan, (scan2 ? scan2 : lineEnd)-scan);
return val;
}
else
{
value += indice;
CHECK(value->type == IniValue::vtString);
return m_stringtable+value->vInt;
}
}
int IniFile::GetValueInt(IniValue *value, UINT indice)
{
if (m_textMode)
{
LPSTR scan = reinterpret_cast<LPSTR>(value);
while (indice)
indice--, scan = strchr(scan,',')+1;
return atoi(scan);
}
else
{
value += indice;
if (value->type == IniValue::vtInt)
return value->vInt;
else if (value->type == IniValue::vtFloat)
return (int) value->vFloat;
else
{
BadType(value-indice, indice, L"integer");
return 0;
}
}
}
LPCTSTR TypeToString(BYTE type)
{
switch (type)
{
case IniValue::vtInt: return L"integer";
case IniValue::vtFloat: return L"float";
case IniValue::vtString: return L"string";
default: return L"invalid type";
}
}
CString IniFile::EntryToString(IniValue *value)
{
BYTE valuesCount = reinterpret_cast<LPBYTE&>(value)[-1];
CString line;
line = m_curEntry+" = ";
while (valuesCount--)
{
switch (value->type)
{
case IniValue::vtInt: line += IntToString(value->vInt); break;
case IniValue::vtFloat: line += FloatToString(value->vFloat); break;
case IniValue::vtString:line += m_stringtable+value->vInt; break;
default: line += "???";
}
if (valuesCount) line += ", ";
value++;
}
return line;
}
void IniFile::BadType(IniValue *value, UINT indice, LPCTSTR expected)
{
ProblemFound(L"%s: [%s] %s has a %s= with argument %d stored as %s instead of %s", m_path, GetCurrentSectionName(), GetValue0(m_curSection, "nickname"), GetValueName(value), indice+1, TypeToString(value->type), expected);
}
float IniFile::GetValueFloat(IniValue *value, UINT indice)
{
if (m_textMode)
{
LPSTR scan = reinterpret_cast<LPSTR>(value);
while (indice)
indice--, scan = strchr(scan,',')+1;
return (float) atof(scan);
}
else
{
value += indice;
if (value->type == IniValue::vtFloat)
return value->vFloat;
else if (value->type == IniValue::vtInt)
return (float) value->vInt;
else
{
BadType(value-indice, indice, L"float");
return 0.0;
}
}
}
DWORD IniFile::GetValueDWORD(IniValue *value, UINT indice)
{
if (m_textMode)
{
LPSTR scan = reinterpret_cast<LPSTR>(value);
while (indice)
indice--, scan = strchr(scan, ',') + 1;
return (DWORD)atof(scan);
}
else
{
value += indice;
if (value->type == IniValue::vtdword)
return value->vtdword;
else if (value->type == IniValue::vtInt)
return (float)value->vInt;
else
{
BadType(value - indice, indice, L"dword");
return 0.0;
}
}
}
void IniFile::LoadFileInResource(int name, int type, DWORD& size, const char*& data)
{
HMODULE handle = ::GetModuleHandle(NULL);
HRSRC rc = ::FindResource(handle, MAKEINTRESOURCE(name),MAKEINTRESOURCE(type));
HGLOBAL rcData = ::LoadResource(handle, rc);
size = ::SizeofResource(handle, rc);
data = static_cast<const char*>(::LockResource(rcData));
}
// Usage example
wchar_t IniFile::GetResource()
{
DWORD size = 0;
DWORD dwWritten = 0;
const char* data = NULL;
LoadFileInResource(IDR_MYTEXTFILE, TEXTFILE, size, data);
/* Access bytes in data - here's a simple example involving text output*/
// The text stored in the resource might not be NULL terminated.
char* buffer = new char[size + 1];
::memcpy(buffer, data, size);
buffer[size] = 0; // NULL terminator
HANDLE iniFile = ::CreateFile(g_basePath + L"tempFLC.ini", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
::WriteFile(iniFile,buffer,size,&dwWritten,NULL); // Print as ASCII text
::CloseHandle(iniFile);
delete[] buffer;
return 0;
}