|
[code]void REG::read_dword()//读取操作表,其类型为DWORD
{
HKEY hKEY;//定义有关的键,在查询结束时关闭
//打开与路径data_Set相关的hKEY
LPCTSTR data_set = _T("Software\\Chicony\\Lenovo1");
//访问注册表,hKEY则保存此函数所打开的键的句柄
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_READ, &hKEY))
{
DWORD dwValue;//长整型数据,如果是字符串数据用char数组
DWORD dwSize = sizeof(DWORD);
DWORD dwType = REG_DWORD;
::RegQueryValueEx(hKEY, _T("123"), 0, &dwType, (LPBYTE)&dwValue, &dwSize);
}
::RegCloseKey(hKEY);
}
CString REG::read_reg_sz()//读取操作表,其类型为REG_SZ
{
HKEY hkey;
LPCTSTR data_set = _T("Software\\TWCAD");
char dwValue[256];
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_READ, &hkey))
{
DWORD dwSzType = REG_SZ;
DWORD dwSize = sizeof(dwValue);
::RegQueryValueEx(hkey, _T("路径"), 0, &dwSzType, (LPBYTE)&dwValue, &dwSize);
}
::RegCloseKey(hkey);
CString dd;
dd.Format(_T("%s"),dwValue);
return dd;
}
void REG::write_dword()//在\Software\\Chicony\\Lenovo1文件夹下写入一个test111的子键,设置其名称为Name,其值为6
{
DWORD dwValue = 6;
DWORD dwSize = sizeof(DWORD);
DWORD dwType = REG_DWORD;
HKEY hKey=NULL;
DWORD dwDisposition;
LPCTSTR data_set= _T("Software\\TWCAD");
long resulte=RegCreateKeyEx(HKEY_CURRENT_USER, data_set, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisposition);
if (ERROR_SUCCESS ==resulte)
{
::RegSetValueEx(hKey, _T("Name"), 0, REG_DWORD, (CONST BYTE*)&dwValue, sizeof(DWORD));
}
::RegCloseKey(hKey);
}
void REG::write_reg_sz(CString strPath)
{
int n =strPath.GetLength( );
ACHAR * m_name_set = NULL;
m_name_set= (ACHAR*)malloc(sizeof(ACHAR)*n);//
_tcscpy(m_name_set, strPath);
DWORD len = n*2 + 1;
LPCTSTR data_set = _T("Software\\TWCAD");
HKEY hKey=NULL;
DWORD dwDisposition;
long resulte=RegCreateKeyEx(HKEY_CURRENT_USER, data_set, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisposition);
if (ERROR_SUCCESS == resulte)
{
::RegSetValueEx(hKey,_T("路径"),0,REG_SZ,(const BYTE*)m_name_set,len);
}
::RegCloseKey(hKey);
}
void REG::write_binary()
{
HKEY hkey;
HKEY hTempKey;
BYTE m_name[10];
memset(m_name, 0, sizeof(m_name));
m_name[0] = 0xff;
m_name[1] = 0xac;
m_name[2] = 0x05;
m_name[3] = 0x4e;
LPCTSTR data_set= _T("Software\\Chicony\\Lenovo1");
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
{
if (ERROR_SUCCESS==::RegCreateKey(hkey,_T("test111"),&hTempKey))
{
::RegSetValueEx(hTempKey, _T("Name"), 0, REG_BINARY, (unsigned char *)m_name, 5);
}
}
::RegCloseKey(hkey);
}
void REG::delete_value()
{
HKEY hkey;
LPCTSTR data_set = _T("Software\\Chicony\\Lenovo1\\test1112");
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
{
::RegDeleteValue(hkey, _T("Name"));
}
::RegCloseKey(hkey);
}
void REG::delete_key()
{
HKEY hkey;
LPCTSTR data_set = _T("Software\\Chicony\\Lenovo1");
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
{
::RegDeleteKey(hkey,_T("test1112"));
}
::RegCloseKey(hkey);
} [/code] |
|