WinApi (ili MFC klase) za registry umeju da budu prilicno konfuzne. U jednom projektu koji sam radio sam malo poludeo od doticnih, i na code projectu sam nasao predivan set klasa za rad sa registry-em:
http://www.codeproject.com/system/caaregistryclass.asp
Jako jednostavno za koriscenje, i ne moras da se patis sa svim glupostima koje je MS napravio oko registry-a.
primer koda:
Code:
CRegistry pReg; ///< deklarisan registry objekt
pReg.OpenKey(CRegistry::localMachine, _T("SOFTWARE\\Neka-Firma\\Nesto\\Common"));
CString dblocation = _T("");
if (!(pReg.GetValue(_T("HomeDir"), dblocation)))
{
/// nema vrednosti, koristi default
}
else
{
/// dobili smo vrednost, bla bla uradi nesto sa time
}
pReg.CloseKey(); ///< zatvori registry
evo i samog hedera klase:
Code:
class CRegistry
{
public:
enum cregRestoreEnum
{
regVolatile = REG_WHOLE_HIVE_VOLATILE,
regRefresh = REG_REFRESH_HIVE,
regNoLazy = REG_NO_LAZY_FLUSH
};
enum Keys
{
classesRoot = HKEY_CLASSES_ROOT,
currentUser = HKEY_CURRENT_USER,
localMachine = HKEY_LOCAL_MACHINE,
currentConfig = HKEY_CURRENT_CONFIG,
users = HKEY_USERS,
performanceData = HKEY_PERFORMANCE_DATA, //Windows NT/2000
dynData = HKEY_DYN_DATA //Windows 95/98
};
CRegistry()
{
m_hKey = NULL;
};
~CRegistry()
{
CloseKey();
m_hKey = NULL;
};
BOOL OpenKey(enum Keys hKey, LPCTSTR szKey);
BOOL CreateKey(enum Keys hKey, LPCTSTR szKey);
BOOL DeleteKey(enum Keys hKey, LPCTSTR szKey);
BOOL DeleteValue(LPCTSTR lpValueName);
BOOL GetValue(LPCTSTR lpValueName, CString& strValue);
BOOL GetValue(LPCTSTR lpValueName, DWORD& dwValue);
BOOL SetValue(LPCTSTR lpValueName, LPCTSTR lpData);
BOOL SetValue(LPCTSTR lpValueName, DWORD dwValue);
BOOL SaveKey(LPCTSTR lpszFileName);
// BOOL RestoreKey(TCHAR lpszFileName, DWORD dwFlag);
// BOOL LoadKey(enum Keys hKey, TCHAR lpszSubKey, TCHAR lpszFileName);
void CloseKey();
protected:
HKEY m_hKey;
};
very easy :)
Za automatsko dobijanje Super Moderatorskog statusa na Elitesecurity forumima pritisnite Alt+F4