Windows registry operationsBasic Code
Reg. h:
# Pragma once
# Include <assert. h>
# Include <windows. h>
Class Reg
{
Hkey;
Public:
Void open (hkey root, char * subkey); // open the registry key. If it does not exist, create
Void del (hkey root, char * subkey); // Delete the registry key
Void close (); // close the registry key
Void setvalue (char * Name, char * data); // set the registry value. If the registry does not exist, create
Void getvalue (char * Name, char * value); // obtain the registry value
Void delvalue (char * Name); // Delete the registry value
};
Void REG: open (hkey root, char * subkey)
{
Long LRET = regcreatekeyex (root, (lpctstr) subkey, 0, null, reg_option_non_volatile, key_all_access, null, & hkey, null );
Assert (LRET = error_success );
}
Void REG: del (hkey root, char * subkey)
{
Long LRET = regdeletekey (root, (lpctstr) subkey );
Assert (LRET = error_success );
}
Void REG: Close ()
{
Long LRET = regclosekey (hkey );
Assert (LRET = error_success );
}
Void REG: setvalue (char * Name, char * Data)
{
Long LRET = regsetvalueex (hkey, (lpctstr) Name, 0, REG_SZ, (byte *) data, (DWORD) strlen (data ));
Assert (LRET = error_success );
}
Void REG: getvalue (char * Name, char * value)
{
Long LRET = regqueryvalueex (hkey, (lpctstr) Name, 0, (lpdword) REG_SZ, (byte *) value, (lpdword) strlen (value ));
Assert (LRET = error_success );
}
Void REG: delvalue (char * name)
{
Long LRET = regdeletevalue (hkey, (lpctstr) Name );
Assert (LRET = error_success );
}
To perform registry operations, you must ensure that the compiler has the Administrator permission. Otherwise, registry operations cannot be performed normally.