// RegistryWrp.cpp : implementation file
//
#include "stdafx.h"
#include "RegistryWrp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define APPLICATION_KEY "Software\\Excoffier\\Notify 1.1"
/////////////////////////////////////////////////////////////////////////////
// CRegistryWrp message handlers
///////////////////////////////////////////////////////////////////////////////////
void CRegistryWrp::WriteKeyToRegistry(CString strRegKey, CString strKey)
{
// Write new string in the registry
HKEY key;
DWORD size, type, disposition;
if (RegOpenKeyEx(HKEY_CURRENT_USER,APPLICATION_KEY,0,
KEY_WRITE,&key)!=ERROR_SUCCESS)
{
RegCreateKeyEx(HKEY_CURRENT_USER,APPLICATION_KEY,0,"",
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,
&key,&disposition);
}
type = REG_SZ;
size = strKey.GetLength();
RegSetValueEx(key,strRegKey,0,type,
(LPBYTE)LPCSTR(strKey),size);
RegCloseKey(key);
}
/////////////////////////////////////////////////////////////////////////////
void CRegistryWrp::WriteKeyToRegistry(CString strRegKey, int nKey)
{
// Write new integer in the registry
HKEY key;
DWORD size, type, disposition;
if (RegOpenKeyEx(HKEY_CURRENT_USER,APPLICATION_KEY,0,
KEY_WRITE,&key)!=ERROR_SUCCESS)
{
RegCreateKeyEx(HKEY_CURRENT_USER,APPLICATION_KEY,0,"",
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,
&key,&disposition);
}
type = REG_DWORD;
size = 4;
RegSetValueEx(key,strRegKey,0,type,(LPBYTE)&nKey,size);
RegCloseKey(key);
}
/////////////////////////////////////////////////////////////////////////////
void CRegistryWrp::GetKeyFromRegistry(CString strRegKey, CString &strKey)
{
// Read new string in the registry
HKEY key;
DWORD size, type;
if (RegOpenKeyEx(
HKEY_CURRENT_USER,APPLICATION_KEY,0,KEY_READ,&key) ==
ERROR_SUCCESS)
{
size=128;
type = REG_SZ;
LPSTR psz = strKey.GetBuffer(size);
RegQueryValueEx(
key,strRegKey,0,&type,(LPBYTE)psz,&size);
strKey.ReleaseBuffer();
RegCloseKey(key);
}
}
/////////////////////////////////////////////////////////////////////////////
void CRegistryWrp::GetKeyFromRegistry(CString strRegKey, int &nKey)
{
// Read new string in the registry
HKEY key;
DWORD size, type;
if (RegOpenKeyEx(
HKEY_CURRENT_USER,APPLICATION_KEY,0,KEY_READ,&key) ==
ERROR_SUCCESS)
{
size=4;
type = REG_DWORD;
RegQueryValueEx(key,strRegKey,0,&type,
(LPBYTE)&nKey,&size);
RegCloseKey(key);
}
}
/////////////////////////////////////////////////////////////////////////////
BOOL CRegistryWrp::IsValueExists(CString strRegKey)
{
// Verify existence of a value in the registry
HKEY hkey;
LONG lReturn=0;
if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_CURRENT_USER, APPLICATION_KEY, 0L, KEY_ALL_ACCESS, &hkey) )
{ lReturn = RegQueryValueEx(HKEY_CURRENT_USER, strRegKey, NULL, NULL, NULL, NULL);
RegCloseKey(hkey);
}
return lReturn;
}
/////////////////////////////////////////////////////////////////////////////
BOOL CRegistryWrp::IsKeyExists(CString strPath)
{
// Verify existence of a key in the registry
HKEY hkey;
BOOL bRet=FALSE;
ASSERT(strPath);
if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_CURRENT_USER, strPath, 0L, KEY_ALL_ACCESS, &hkey) )
{ bRet=TRUE;
RegCloseKey(hkey);
}
return bRet;
}
/////////////////////////////////////////////////////////////////////////////
BOOL CRegistryWrp::CreateKey(CString strPath)
{
// Create a new key in the registry
HKEY key;
DWORD disposition;
BOOL bRet=FALSE;
if (RegOpenKeyEx(HKEY_CURRENT_USER,strPath,0,
KEY_WRITE,&key)!=ERROR_SUCCESS)
{
RegCreateKeyEx(HKEY_CURRENT_USER,strPath,0,"",
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,
&key,&disposition);
bRet = TRUE;
RegCloseKey(key);
}
return bRet;
}
/////////////////////////////////////////////////////////////////////////////