⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regoperater.cpp

📁 T3G的TD-SCDMA平台的驱动安装
💻 CPP
字号:
//------------------------------------------------------------------------------
//	created:	2008-5=19  16:03
//	author:		xqzhou
//------------------------------------------------------------------------------
#include "stdafx.h"
#include "RegOperater.h"
CRegOperate::CRegOperate()
{
	
}
CRegOperate::~CRegOperate()
{
	
}
CRegOperate::err CRegOperate::SetStrValue(HKEY hMainKey, CString szSubKey, CString szItem,  CString szValue)
{
	HKEY hRsltKey;
	
	//=========================================打开注册表
	long lRslt = RegOpenKey(hMainKey, szSubKey, &hRsltKey);
	if (lRslt != ERROR_SUCCESS)
	{   
		return this->ERR_OPENREGKEY;
	}
	
	//===================================设置注册表值
	lRslt = RegSetValueEx(hRsltKey, szItem, NULL, REG_SZ,
		LPBYTE(szValue.GetBuffer(szValue.GetLength())), szValue.GetLength());
	if (lRslt != ERROR_SUCCESS)
	{   
		return ERR_SETREGVALUE;
	}
	
	//============================================关闭注册表键
	if (hMainKey)
	{
		RegCloseKey(hMainKey);
	}
	if (hRsltKey)
	{
		RegCloseKey(hRsltKey);
	}
	return ERR_SUCCESS;
}

CRegOperate::err CRegOperate::GetStrValue(HKEY hMainKey, CString szSubKey, CString szItem, CString& szValue)
{  
	HKEY hRsltKey;
	//打开注册表
	if (ERROR_SUCCESS != RegOpenKey(hMainKey, szSubKey, &hRsltKey))
	{   
		return ERR_OPENREGKEY;
	}
	LPBYTE lpData = new BYTE[256];
	DWORD dwType = REG_SZ;
	DWORD dwNum = 256;
	//查询注册表项值
	long lRslt = RegQueryValueEx(hRsltKey, szItem, NULL, &dwType, lpData, &dwNum);
	if (lRslt != ERROR_SUCCESS)
	{   
		return ERR_QUERYVALUE;
	}
	szValue = (CString)lpData; 
	//关闭打开的键
	if (hMainKey)
	{
		RegCloseKey(hMainKey);
	}
	if (hRsltKey)
	{
		RegCloseKey(hRsltKey);
	}
	return ERR_SUCCESS;
}

CRegOperate::err CRegOperate::AddSubKey(HKEY hMainKey, CString szSubKey)
{
	HKEY hRsltKey;
	//================================判断要增加的注册表子键是否已存在
	if (ERROR_SUCCESS == RegOpenKey(hMainKey, szSubKey, &hRsltKey))
	{  
		return this->ERR_SUBKEYEXIST;
	}
	
	//==================================如果不存在,则增加此子键
	long lRslt = RegCreateKey(hMainKey, szSubKey, &hRsltKey);
	// long lCrtRslt = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\WZJ", &hRsltKey);
	
	if (lRslt != ERROR_SUCCESS) 
	{  
		return this->ERR_CREATESUBKEY;  
	}
	
	//===============================关闭打开的注册表键句柄
	if(hMainKey)
	{
		RegCloseKey(hMainKey);
	}
	if (hRsltKey) 
	{
		RegCloseKey(hRsltKey);
	}
	return this->ERR_SUCCESS;
} 

CRegOperate::err CRegOperate::DeleteStrValue(HKEY hMainKey, CString szSubKey, CString szItem)
{
	HKEY hRsltKey;
	//打开注册表
	long lRslt = RegOpenKey(hMainKey, szSubKey, &hRsltKey);
	if (lRslt != ERROR_SUCCESS)
	{  
		return ERR_OPENREGKEY;
	}
	//删除注册表项
	lRslt = RegDeleteValue(hRsltKey, szItem);
	if (lRslt != ERROR_SUCCESS)
	{  
		return ERR_DELETEVALUE;
	}
	return ERR_SUCCESS;
}

CRegOperate::err CRegOperate::DeleteSubKey(HKEY hMainKey, CString szSubKey)
{
	//=================================删除子键
	long lRslt = RegDeleteKey(hMainKey, szSubKey);
	if (lRslt) {  
		return ERR_DELETESUBKEY;
	}
	
	//关闭打开的键
	if (hMainKey)
	{
		RegCloseKey(hMainKey);
	}
	return ERR_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -