uLib  User mode C/C++ extended API library for Win32 programmers.
IniFile.h
Go to the documentation of this file.
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // Project: uLib - User mode utility library.
3 // Module: INI file support class. (Ini files are portable, registry is not.)
4 // Author: Copyright (c) Love Nystrom
5 // License: NNOSL (BSD descendant, see NNOSL.txt in the base directory).
6 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 
8 // Note: Due to my unwillingness to swell the header too much vertically, which
9 // would hamper overview, the doxygen comments result in long lines instead.
10 
11 #ifndef _IniFile_h_incl_
12 #define _IniFile_h_incl_
13 
14 #include <uLib/Common.h>
15 
20 
21 typedef class IniFile* PIniFile;
22 //
28 //
29 class IniFile {
30 protected:
32  PBYTE _buffer;
33  UINT _bufSize;
34  INT _valSize; // Negative = Buffer insufficient on last call.
36 public:
37  TCHAR Filename[ MAX_PATH ];
38  UINT_PTR UserData;
39 
41 
42  IniFile( CSTR FName=NULL, UINT BufSize=4096 );
43  virtual ~IniFile();
44 
47 
48  void SetFilename( CSTR FName );
49 
51 
52  bool AllocBuffer( UINT Size );
53  UINT BufSize() { return _bufSize; }
54  PBYTE GetBuffer() { return _buffer; }
55 
56  // Ini files are typically ANSI (char) text files.
57  // TODO: Check how ini functions react to wchar_t files..
58 
59  operator LPCSTR() { return (LPCSTR)_buffer; }
60  operator LPSTR() { return (LPSTR)_buffer; }
61 
65 
66  INT ValSize() { return _valSize; }
67 
68  UINT GetInt( CSTR Section, CSTR KeyName, INT Default );
69  INT GetString( CSTR Section, CSTR KeyName, CSTR Default, TSTR Buf, UINT BufLen );
70  TSTR GetString( CSTR Section, CSTR KeyName, CSTR Default, OPTOUT INT* Size = NULL );
71  TSTR GetSection( CSTR Section, OPTOUT INT* Size = NULL );
72  TSTR GetSectionNames( OPTOUT INT* Size = NULL );
73 
78 
79  PBYTE GetBinary( CSTR Section, CSTR Key, OUT INT* pSize );
81  PBYTE GetStruct( CSTR Section, CSTR Key, UINT cbStruct );
82 
86 
87  BOOL WriteRawSection( CSTR Section, CSTR MultiSz );
88  BOOL WriteSection( CSTR Section, CSTR Strings );
89  BOOL WriteString( CSTR Section, CSTR KeyName, CSTR Text );
90 
93 
94  BOOL WriteStringFmt( CSTR Section, CSTR KeyName, CSTR Fmt, ... );
95 
96  BOOL WriteInt( CSTR Section, CSTR KeyName, LONG Value, BYTE Radix=10 );
97  BOOL WriteStruct( CSTR Section, CSTR Key, PVOID pStruct, UINT Size );
98 
99  BOOL DeleteString( CSTR Section, CSTR KeyName );
100  BOOL DeleteSection( CSTR Section );
101 
102  // Common chores..
103 
104  BOOL SaveWndRect( HWND hWnd, CSTR Section, CSTR Key );
105  BOOL RestoreWndRect( HWND hWnd, CSTR Section, CSTR Key );
106 };
107 
109 #endif//ndef _IniFile_h_incl_
110 // EOF
UINT BufSize()
Definition: IniFile.h:53
TCHAR Filename[MAX_PATH]
Definition: IniFile.h:37
void SetFilename(CSTR FName)
Definition: IniFile.cpp:27
#define CSTR
Definition: Common.h:329
BOOL WriteStringFmt(CSTR Section, CSTR KeyName, CSTR Fmt,...)
Definition: IniFile.cpp:300
PBYTE GetBinary(CSTR Section, CSTR Key, OUT INT *pSize)
Definition: IniFile.cpp:147
PBYTE GetStruct(CSTR Section, CSTR Key, UINT cbStruct)
Definition: IniFile.cpp:125
#define TSTR
Definition: Common.h:328
unsigned char * PBYTE
Definition: Common.h:412
UINT_PTR UserData
Definition: IniFile.h:38
BOOL SaveWndRect(HWND hWnd, CSTR Section, CSTR Key)
Definition: IniFile.cpp:330
#define OPTOUT
Definition: Common.h:264
TSTR GetSectionNames(OPTOUT INT *Size=NULL)
Definition: IniFile.cpp:110
INT GetString(CSTR Section, CSTR KeyName, CSTR Default, TSTR Buf, UINT BufLen)
Definition: IniFile.cpp:71
PBYTE GetBuffer()
Definition: IniFile.h:54
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
BOOL WriteString(CSTR Section, CSTR KeyName, CSTR Text)
Definition: IniFile.cpp:295
BOOL WriteSection(CSTR Section, CSTR Strings)
Definition: IniFile.cpp:173
BOOL DeleteSection(CSTR Section)
Definition: IniFile.cpp:323
BOOL DeleteString(CSTR Section, CSTR KeyName)
Definition: IniFile.cpp:318
UINT GetInt(CSTR Section, CSTR KeyName, INT Default)
Definition: IniFile.cpp:66
INT ValSize()
Definition: IniFile.h:66
IniFile(CSTR FName=NULL, UINT BufSize=4096)
Definition: IniFile.cpp:15
Common include; Added types, small "ubiquitous" utilities, et c.
class IniFile * PIniFile
Definition: IniFile.h:21
virtual ~IniFile()
Definition: IniFile.cpp:22
BOOL WriteInt(CSTR Section, CSTR KeyName, LONG Value, BYTE Radix=10)
Definition: IniFile.cpp:283
bool AllocBuffer(UINT Size)
Definition: IniFile.cpp:43
BOOL WriteStruct(CSTR Section, CSTR Key, PVOID pStruct, UINT Size)
Definition: IniFile.cpp:313
BOOL RestoreWndRect(HWND hWnd, CSTR Section, CSTR Key)
Definition: IniFile.cpp:342
BOOL WriteRawSection(CSTR Section, CSTR MultiSz)
Definition: IniFile.cpp:202
TSTR GetSection(CSTR Section, OPTOUT INT *Size=NULL)
Definition: IniFile.cpp:95
unsigned char BYTE
Definition: Common.h:412