uLib  User mode C/C++ extended API library for Win32 programmers.
Registry Support Functions

Module Description

Supplements to the advapi32 registry functions.
#include <uLib/RegFunc.h>

Macros

#define KEY_CONTROL   (DELETE| READ_CONTROL| WRITE_DAC| WRITE_OWNER)
 
#define KEY_RW   (KEY_READ|KEY_WRITE)
 
#define ALL_SECURITY_INFO
 
#define REG_OK(rc)   (rc == NOERROR)
 
#define REG_ERR(rc)   (rc != NOERROR)
 
#define RegQueryDefaultValue(hKey, pType, pData, pSize)   RegQueryValueEx( hKey, _T(""), 0, pType, pData, pSize )
 
#define RegQuerySubkeys(hKey, pNrKeys, pCcKeyname)   RegQueryInfoKey( hKey, 0,0,0, pNrKeys, pCcKeyname, 0,0,0,0,0,0 )
 

Functions

HKEY RegCloseKeyEx (HKEY Key)
 
BOOL RegKeyExist (HKEY BaseKey, CSTR RegPath)
 
BOOL RegValueExist (HKEY hKey, CSTR Name)
 
LONG RegDeleteBranch (HKEY Parent, CSTR SubkeyName)
 
LONG _RegRenameKey (HKEY BaseKey, CSTR Subkey, CSTR NewSubkeyName)
 
LONG RegRenameValue (HKEY hKey, CSTR OldName, CSTR NewName)
 
CSTR RegSysKeyName (HKEY hkey)
 
CSTR RegSysKeyAcronym (HKEY hkey)
 
CSTR RegTypeName (DWORD type)
 
CSTR RegValueName (CSTR name)
 
LONG RegSetDWord (HKEY hKey, CSTR ValName, DWORD Val)
 
LONG RegGetDWord (HKEY hKey, CSTR ValName, PDWORD pVal)
 
LONG RegGetUInt (HKEY hKey, CSTR ValName, PUINT pVal)
 
LONG RegGetBool (HKEY hKey, CSTR ValName, bool *pVal)
 
LONG RegSetBinary (HKEY hKey, CSTR ValName, PBYTE Val, DWORD Size)
 
LONG RegGetBinary (HKEY hKey, CSTR ValName, PBYTE pVal, PDWORD pSize)
 
LONG RegSetString (HKEY hKey, CSTR ValName, CSTR Str, DWORD Type)
 
LONG RegGetString (HKEY hKey, CSTR ValName, TSTR Buf, PDWORD Size, PDWORD Type)
 
LONG SaveWindowRect (HWND hWnd, HKEY baseKey, CSTR regPath, CSTR valName)
 
LONG RestoreWindowRect (HWND hWnd, HKEY baseKey, CSTR regPath, CSTR valName)
 

Macro Definition Documentation

◆ KEY_CONTROL

#define KEY_CONTROL   (DELETE| READ_CONTROL| WRITE_DAC| WRITE_OWNER)

Definition at line 23 of file RegFunc.h.

◆ KEY_RW

#define KEY_RW   (KEY_READ|KEY_WRITE)

Definition at line 25 of file RegFunc.h.

◆ ALL_SECURITY_INFO

#define ALL_SECURITY_INFO
Value:
( OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION \
| DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION )

Definition at line 29 of file RegFunc.h.

◆ REG_OK

#define REG_OK (   rc)    (rc == NOERROR)

Definition at line 34 of file RegFunc.h.

◆ REG_ERR

#define REG_ERR (   rc)    (rc != NOERROR)

Definition at line 35 of file RegFunc.h.

◆ RegQueryDefaultValue

#define RegQueryDefaultValue (   hKey,
  pType,
  pData,
  pSize 
)    RegQueryValueEx( hKey, _T(""), 0, pType, pData, pSize )

RegQueryDefaultValue gets the default value for the key.
Unlike RegQueryValue, this one queries an open key.

Definition at line 62 of file RegFunc.h.

◆ RegQuerySubkeys

#define RegQuerySubkeys (   hKey,
  pNrKeys,
  pCcKeyname 
)    RegQueryInfoKey( hKey, 0,0,0, pNrKeys, pCcKeyname, 0,0,0,0,0,0 )

RegQuerySubkeys gets subkey count and length of longest subkey name.
Either parameter may be NULL if you don't need it's content.

Parameters
hKeyAn open or predefined key.
pNrKeysPointer to a dword that receives the subkey count.
pCcKeynamePointer to a dword that recieves char count.

Definition at line 71 of file RegFunc.h.

Function Documentation

◆ RegCloseKeyEx()

HKEY RegCloseKeyEx ( HKEY  Key)

RegCloseKeyEx closes the Key and returns NULL on success (like LocalFree).
On failure it calls SetLastError and returns Key as-is.

Parameters
KeyAn open registry key.

Definition at line 22 of file RegFunc.cpp.

◆ RegKeyExist()

BOOL RegKeyExist ( HKEY  BaseKey,
CSTR  RegPath 
)

RegKeyExist returns TRUE if the specified key exists.

Parameters
BaseKeyAn open or predefined key.
RegPathA subkey path under BaseKey.

Definition at line 35 of file RegFunc.cpp.

◆ RegValueExist()

BOOL RegValueExist ( HKEY  hKey,
CSTR  Name 
)

RegValueExist checks if the value exist.

Parameters
hKeyAn open or predefined key.
NameThe value name.

Definition at line 46 of file RegFunc.cpp.

◆ RegDeleteBranch()

LONG RegDeleteBranch ( HKEY  Parent,
CSTR  SubkeyName 
)

RegDeleteBranch recursively deletes a key and all it's sub-keys.
(Works like SHDeleteKey(), but doesn't need the shell API.)

Parameters
ParentAn open or predefined key.
SubkeyNameName of a subkey to delete.

Definition at line 213 of file RegFunc.cpp.

◆ _RegRenameKey()

LONG _RegRenameKey ( HKEY  BaseKey,
CSTR  Subkey,
CSTR  NewSubkeyName 
)

_RegRenameKey renames a registry subkey, preserving class and security settings.

Parameters
BaseKeyAn open or predefined key
SubkeyExisting subkey pathname
NewSubkeyNameNew subkey pathname

_RegRenameKey() works, due to registry design necessity, by copying the whole
branch, retaining security settings et c, to a new key with NewSubKeyName.
The interim branch copy is held temporarily in a RegSaveKey subhive file.

Note: As of SDK 7.0, RegRenameKey() is available, as Unicode only,
so this legacy function was renamed _RegRenameKey to avert the name clash.
uLib's _RegRenameKey() predates RegRenameKey[W], and was originally written
for WinNT4/2k/XP.

NT Insight
Internally, Microsoft's "new" RegRenameKey[W] uses the native NtRenameKey() API
exported by NTDLL. From the MSDN remark on NtRenameKey:
*The caller must have KEY_CREATE_SUB_KEY access to the parent of the specified key
and DELETE access to the entire subtree being renamed*, it's easy to surmise that
NtRenameKey does internally exactly what uLib's _RegRenameKey() does.

Definition at line 301 of file RegFunc.cpp.

◆ RegRenameValue()

LONG RegRenameValue ( HKEY  hKey,
CSTR  OldName,
CSTR  NewName 
)

RegRenameValue renames a registry value.

Definition at line 71 of file RegFunc.cpp.

◆ RegSysKeyName()

CSTR RegSysKeyName ( HKEY  hkey)

RegSysKeyName(), RegSysKeyAcronym(), and RegTypeName(), returns
human readable string representations for predefined registry constants.

Return e.g. "HKEY_LOCAL_MACHINE", or NULL.

Definition at line 440 of file RegFunc.cpp.

◆ RegSysKeyAcronym()

CSTR RegSysKeyAcronym ( HKEY  hkey)

Return e.g. "HKLM", or NULL

Definition at line 467 of file RegFunc.cpp.

◆ RegTypeName()

CSTR RegTypeName ( DWORD  type)

Return e.g. "REG_DWORD", or NULL.

Definition at line 493 of file RegFunc.cpp.

◆ RegValueName()

CSTR RegValueName ( CSTR  name)

If 'name' is a non-empty string, it is returned verbatim,
else if NULL, "(null)" is returned, or if empty, "(default)" is returned.

Definition at line 516 of file RegFunc.cpp.

◆ RegSetDWord()

LONG RegSetDWord ( HKEY  hKey,
CSTR  ValName,
DWORD  Val 
)

Definition at line 95 of file RegFunc.cpp.

◆ RegGetDWord()

LONG RegGetDWord ( HKEY  hKey,
CSTR  ValName,
PDWORD  pVal 
)

Definition at line 100 of file RegFunc.cpp.

◆ RegGetUInt()

LONG RegGetUInt ( HKEY  hKey,
CSTR  ValName,
PUINT  pVal 
)

Definition at line 111 of file RegFunc.cpp.

◆ RegGetBool()

LONG RegGetBool ( HKEY  hKey,
CSTR  ValName,
bool *  pVal 
)

Definition at line 116 of file RegFunc.cpp.

◆ RegSetBinary()

LONG RegSetBinary ( HKEY  hKey,
CSTR  ValName,
PBYTE  Val,
DWORD  Size 
)

Definition at line 126 of file RegFunc.cpp.

◆ RegGetBinary()

LONG RegGetBinary ( HKEY  hKey,
CSTR  ValName,
PBYTE  pVal,
PDWORD  pSize 
)

Definition at line 131 of file RegFunc.cpp.

◆ RegSetString()

LONG RegSetString ( HKEY  hKey,
CSTR  ValName,
CSTR  Str,
DWORD  Type 
)

Definition at line 144 of file RegFunc.cpp.

◆ RegGetString()

LONG RegGetString ( HKEY  hKey,
CSTR  ValName,
TSTR  Buf,
PDWORD  Size,
PDWORD  Type 
)

Definition at line 151 of file RegFunc.cpp.

◆ SaveWindowRect()

LONG SaveWindowRect ( HWND  hWnd,
HKEY  baseKey,
CSTR  regPath,
CSTR  valName 
)

Save/Restore window position and size from registry.
Do not use on child windows.

Definition at line 167 of file RegFunc.cpp.

◆ RestoreWindowRect()

LONG RestoreWindowRect ( HWND  hWnd,
HKEY  baseKey,
CSTR  regPath,
CSTR  valName 
)

See SaveWindowRect().

Definition at line 184 of file RegFunc.cpp.