#include "StdAfx.h" #include #include #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #define new DEBUG_NEW #endif HKEY OpenKeySection(const TCHAR *i_Section) { HKEY hKey = NULL; if(i_Section) { RegOpenKeyEx(HKEY_LOCAL_MACHINE, i_Section, 0, KEY_WRITE|KEY_READ, &hKey); if(!hKey) { DWORD dw; RegCreateKeyEx(HKEY_LOCAL_MACHINE, i_Section, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw); } } return hKey; } bool ReadRegKey(const TCHAR *i_Section, const TCHAR *i_Key, int &o_Value) { bool ReadOK = false; if(i_Section) { HKEY hKey = OpenKeySection(i_Section); if(hKey) { DWORD dwType; DWORD dwCount; LONG lResult = RegQueryValueEx(hKey, i_Key, NULL, &dwType, NULL, &dwCount); if(lResult == ERROR_SUCCESS && dwType == REG_DWORD) { lResult = RegQueryValueEx(hKey, i_Key, NULL, &dwType, (LPBYTE)&o_Value, &dwCount); ReadOK = true; } RegCloseKey(hKey); } } return ReadOK; } void WriteRegKey(const TCHAR *i_Section, const TCHAR *i_Key, int i_Value) { if(i_Section) { HKEY hKey = OpenKeySection(i_Section); if(hKey) { RegSetValueEx(hKey, i_Key, NULL, REG_DWORD, (LPBYTE)&i_Value, sizeof(i_Value)); RegCloseKey(hKey); } } } void DeleteRegKey(const TCHAR *i_Section, const TCHAR *i_Key) { if(i_Section) { HKEY hKey = OpenKeySection(i_Section); if(hKey) { /*LONG lResult = */RegDeleteKey(hKey, i_Key); } } }