uLib  User mode C/C++ extended API library for Win32 programmers.
IniFile Class Reference

#include <uLib/IniFile.h>

Detailed Description

IniFile encapsulates the Get/WritePrivateProfile function family.
It also provides some additional functionality not provided by the system.
IniFile uses an internal data buffer for data retrieval and formatting.
After instanciation, use AllocBuffer() if you need to resize the buffer.
Do size the buffer to fit the biggest block you expect. The default is 4 kB.

Definition at line 29 of file IniFile.h.

Public Data

TCHAR Filename [MAX_PATH]
 
UINT_PTR UserData
 

Public Functions

 IniFile (CSTR FName=NULL, UINT BufSize=4096)
 
virtual ~IniFile ()
 
void SetFilename (CSTR FName)
 
bool AllocBuffer (UINT Size)
 
UINT BufSize ()
 
PBYTE GetBuffer ()
 
 operator LPCSTR ()
 
 operator LPSTR ()
 
INT ValSize ()
 
UINT GetInt (CSTR Section, CSTR KeyName, INT Default)
 
INT GetString (CSTR Section, CSTR KeyName, CSTR Default, TSTR Buf, UINT BufLen)
 
TSTR GetString (CSTR Section, CSTR KeyName, CSTR Default, OPTOUT INT *Size=NULL)
 
TSTR GetSection (CSTR Section, OPTOUT INT *Size=NULL)
 
TSTR GetSectionNames (OPTOUT INT *Size=NULL)
 
PBYTE GetBinary (CSTR Section, CSTR Key, OUT INT *pSize)
 
PBYTE GetStruct (CSTR Section, CSTR Key, UINT cbStruct)
 
BOOL WriteRawSection (CSTR Section, CSTR MultiSz)
 
BOOL WriteSection (CSTR Section, CSTR Strings)
 
BOOL WriteString (CSTR Section, CSTR KeyName, CSTR Text)
 
BOOL WriteStringFmt (CSTR Section, CSTR KeyName, CSTR Fmt,...)
 
BOOL WriteInt (CSTR Section, CSTR KeyName, LONG Value, BYTE Radix=10)
 
BOOL WriteStruct (CSTR Section, CSTR Key, PVOID pStruct, UINT Size)
 
BOOL DeleteString (CSTR Section, CSTR KeyName)
 
BOOL DeleteSection (CSTR Section)
 
BOOL SaveWndRect (HWND hWnd, CSTR Section, CSTR Key)
 
BOOL RestoreWndRect (HWND hWnd, CSTR Section, CSTR Key)
 

Constructor & Destructor Documentation

◆ IniFile()

IniFile::IniFile ( CSTR  FName = NULL,
UINT  BufSize = 4096 
)

Initialize Filename and allocate a buffer. Calls SetFilename().

Definition at line 15 of file IniFile.cpp.

◆ ~IniFile()

IniFile::~IniFile ( )
virtual

Dispose the internal buffer.

Definition at line 22 of file IniFile.cpp.

Member Function Documentation

◆ SetFilename()

void IniFile::SetFilename ( CSTR  FName)

SetFilename sets the INI Filename to use.
If FName is NULL, GetModuleFileName() is used, replacing .exe with .ini.

Definition at line 27 of file IniFile.cpp.

◆ AllocBuffer()

bool IniFile::AllocBuffer ( UINT  Size)

AllocBuffer (re)allocates the internal buffer.

Definition at line 43 of file IniFile.cpp.

◆ BufSize()

UINT IniFile::BufSize ( )
inline

Get the current buffer size.

Definition at line 53 of file IniFile.h.

◆ GetBuffer()

PBYTE IniFile::GetBuffer ( )
inline

Get the current buffer.

Definition at line 54 of file IniFile.h.

◆ operator LPCSTR()

IniFile::operator LPCSTR ( )
inline

The current buffer as a LPCSTR.

Definition at line 59 of file IniFile.h.

◆ operator LPSTR()

IniFile::operator LPSTR ( )
inline

The current buffer as a LPSTR.

Definition at line 60 of file IniFile.h.

◆ ValSize()

INT IniFile::ValSize ( )
inline

Return the size of the last GetString(), GetSection(), or GetSectionNames().
If the value is negative, the buffer was too small, and the abs value indicate the required buffer size.

Definition at line 66 of file IniFile.h.

◆ GetInt()

UINT IniFile::GetInt ( CSTR  Section,
CSTR  KeyName,
INT  Default 
)

GetInt can handle radix 10 and 16.

Definition at line 66 of file IniFile.cpp.

◆ GetString() [1/2]

INT IniFile::GetString ( CSTR  Section,
CSTR  KeyName,
CSTR  Default,
TSTR  Buf,
UINT  BufLen 
)

GetPrivateProfileString().

Definition at line 71 of file IniFile.cpp.

◆ GetString() [2/2]

TSTR IniFile::GetString ( CSTR  Section,
CSTR  KeyName,
CSTR  Default,
OPTOUT INT *  Size = NULL 
)

GetPrivateProfileString().

◆ GetSection()

TSTR IniFile::GetSection ( CSTR  Section,
OPTOUT INT *  Size = NULL 
)

Returns a multi-sz with all key/value pairs.

Definition at line 95 of file IniFile.cpp.

◆ GetSectionNames()

TSTR IniFile::GetSectionNames ( OPTOUT INT *  Size = NULL)

Returns a multi-sz with all section names.

Definition at line 110 of file IniFile.cpp.

◆ GetBinary()

PBYTE IniFile::GetBinary ( CSTR  Section,
CSTR  Key,
OUT INT *  pSize 
)

GetBinary is a variant of GetStruct() that doesn't need a specified size.
Instead, the whole hex string is read and processed, and the function
returns both the parsed binary data and it's size.
In case of a checksum error, the return value is NULL.

Definition at line 147 of file IniFile.cpp.

◆ GetStruct()

PBYTE IniFile::GetStruct ( CSTR  Section,
CSTR  Key,
UINT  cbStruct 
)

GetStruct simply uses GetPrivateProfileStruct() with the internal buffer.

Definition at line 125 of file IniFile.cpp.

◆ WriteRawSection()

BOOL IniFile::WriteRawSection ( CSTR  Section,
CSTR  MultiSz 
)

WriteRawSection() replaces a section verbatim (no key/value parsing).

Note
Your MultiSz can not contain any embedded '[', or the function will fail
with unpredictable results, due to interpreting the '[' as the next section heading!

Definition at line 202 of file IniFile.cpp.

◆ WriteSection()

BOOL IniFile::WriteSection ( CSTR  Section,
CSTR  Strings 
)

WritePrivateProfileSection()

Definition at line 173 of file IniFile.cpp.

◆ WriteString()

BOOL IniFile::WriteString ( CSTR  Section,
CSTR  KeyName,
CSTR  Text 
)

WritePrivateProfileString()

Definition at line 295 of file IniFile.cpp.

◆ WriteStringFmt()

BOOL IniFile::WriteStringFmt ( CSTR  Section,
CSTR  KeyName,
CSTR  Fmt,
  ... 
)

Format the arguments with _vstprintf_s() into the internal buffer
and write it out as a string value.

Definition at line 300 of file IniFile.cpp.

◆ WriteInt()

BOOL IniFile::WriteInt ( CSTR  Section,
CSTR  KeyName,
LONG  Value,
BYTE  Radix = 10 
)

Radix = 10 or 16.

Definition at line 283 of file IniFile.cpp.

◆ WriteStruct()

BOOL IniFile::WriteStruct ( CSTR  Section,
CSTR  Key,
PVOID  pStruct,
UINT  Size 
)

WritePrivateProfileStruct().

Definition at line 313 of file IniFile.cpp.

◆ DeleteString()

BOOL IniFile::DeleteString ( CSTR  Section,
CSTR  KeyName 
)

Delete the KeyName value.

Definition at line 318 of file IniFile.cpp.

◆ DeleteSection()

BOOL IniFile::DeleteSection ( CSTR  Section)

Delete the entire Section.

Definition at line 323 of file IniFile.cpp.

◆ SaveWndRect()

BOOL IniFile::SaveWndRect ( HWND  hWnd,
CSTR  Section,
CSTR  Key 
)

Save the window rect.

Definition at line 330 of file IniFile.cpp.

◆ RestoreWndRect()

BOOL IniFile::RestoreWndRect ( HWND  hWnd,
CSTR  Section,
CSTR  Key 
)

Restore the window rect.

Definition at line 342 of file IniFile.cpp.

Member Data Documentation

◆ Filename

TCHAR IniFile::Filename[MAX_PATH]

Ini file path name.

Definition at line 37 of file IniFile.h.

◆ UserData

UINT_PTR IniFile::UserData

Arbitrary user data..

Definition at line 38 of file IniFile.h.


The documentation for this class was generated from the following files: