![]() |
General Reading »
Hardware & System »
Registry
Intermediate
A Registry ClassBy Carlos AntolliniA class that makes it easy to work with the registry |
VC6Win2K, Visual Studio, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
I created this class to make it easy to work
with the Registry. For this I created the CRegistry class.
The CRegistry class has a set of functions that make using the
registry easy.
The OpenKey opens the specified registry key.
BOOL OpenKey(enum Keys hKey, LPCTSTR szKey);
enum Keys hKey - Handle to any of the following predefined values:
CRegistry::classesRoot
CRegistry::currentUser
CRegistry::localMachine
CRegistry::currentConfig
CRegistry::usersWindows NT/2000:
CRegistry::performanceDataWindows 95/98:
CRegistry::dynData
LPCTSTR szKey - Pointer to a null-terminated string containing the name of the key to open.
If the function succeeds, this returns TRUE.
"Sample1"> CRegistry pReg; pReg.OpenKey(CRegistry::currentUser, "Entry1\\carlos1"); CString str = _T(""); if(pReg.GetValue("SZVAL1", str)) AfxMessageBox("The Value SZVAL1 don't exists", MB_ICONWARNING); DWORD dwVal = 0; pReg.GetValue("DWVAL", dwVal); pReg.GetValue(NULL, str); pReg.CloseKey();
The CreateKey function creates the specified registry key. If the key already exists in the registry,
the function opens it.
BOOL CreateKey(enum Keys hKey, LPCTSTR szKey);
enum Keys hKey - Handle to any of the following predefined values:
CRegistry::classesRoot
CRegistry::currentUser
CRegistry::localMachine
CRegistry::currentConfig
CRegistry::usersWindows NT/2000:
CRegistry::performanceDataWindows 95/98:
CRegistry::dynData
LPCTSTR szKey - Pointer to a null-terminated string containing the name of the key to open or
create.
If the function succeeds, this returns TRUE.
The DeleteKey function deletes a subkey.
BOOL DeleteKey(enum Keys hKey, LPCTSTR szKey);
enum Keys hKey - Handle to any of the following predefined values:
CRegistry::classesRoot
CRegistry::currentUser
CRegistry::localMachine
CRegistry::currentConfig
CRegistry::usersWindows NT/2000:
CRegistry::performanceDataWindows 95/98:
CRegistry::dynData
LPCTSTR szKey - Pointer to a null-terminated string containing the name of the key to delete.
If the function succeeds, this returns TRUE.
The GetValue function retrieves the data for a specified value name from the open registry key.
BOOL GetValue(LPCTSTR lpValueName, CString& strValue); BOOL GetValue(LPCTSTR lpValueName, DWORD& dwValue);
LPCTSTR lpValueName - Pointer to a null-terminated string containing the name of the value to get
CString& strValue - Pointer to a buffer that receives the value's data
DWORD& dwValue - Pointer to a buffer that receives the value's data
If the function succeeds, this returns TRUE.
The SetValue function sets the data and type of a specified value
under a registry key.
BOOL SetValue(LPCTSTR lpValueName, LPCTSTR lpData); BOOL SetValue(LPCTSTR lpValueName, DWORD dwValue);
LPCTSTR lpValueName - Pointer to a null-terminated string containing the name of the value to
set
CString& strValue - Pointer to a buffer containing the data to be stored with the specified value
name
DWORD& dwValue - Pointer to a buffer containing the data to be stored with the specified value
name
If the function succeeds, this returns TRUE.
"Sample2">pReg.OpenKey(CRegistry::currentUser, "Entry1\\carlos1"); pReg.SetValue("SZVAL", "STRVAL"); pReg.SetValue(NULL, "default"); pReg.SetValue("DWVAL", 34); pReg.CloseKey();
The DeleteValue function removes a named value from the specified registry key
BOOL DeleteValue(LPCTSTR lpValueName);
LPCTSTR lpValueName - Pointer to a null-terminated string that names the value to remove.
If the function succeeds, this returns TRUE.
"Sample3"> CRegistry pReg; pReg.OpenKey(CRegistry::currentUser, "Entry1\\carlos1"); pReg.DeleteValue("SZVAL"); pReg.CloseKey();
The CloseKey function closes the registry key.
void CloseKey();
04 August 2001: Version 1.0 Released.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Aug 2001 Editor: Brian Delahunty |
Copyright 2001 by Carlos Antollini Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |