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

📄 reg.cpp

📁 一个手机通信的源代码 一个手机通信的源代码一个手机通信的源代码
💻 CPP
字号:
// Reg.cpp: implementation of the CReg class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Reg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//我们在HKEY_LOCAL_MACHINE\SOFTWARE 下进行设置
//进行读和写。
CReg::CReg()
{
}

CReg::~CReg()
{

}

LONG CReg::SetKey(CString csPath, CString csName, CString csValue)
{
  HKEY  hKey1; 
  DWORD  dwDisposition; 
  LONG   lRetCode; 
  CString cstemp="SOFTWARE\\";
  cstemp.Format("SOFTWARE\\%s",csPath);

  lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE,cstemp,0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey1, &dwDisposition); 
  
  // if we failed, note it, and leave return errID
  if (lRetCode != ERROR_SUCCESS){ 
      return lRetCode;
    } 

  //设置值
  BYTE *d=(BYTE *)csValue.GetBuffer(csValue.GetLength());  
  lRetCode = RegSetValueEx ( hKey1, csName,  0,REG_SZ, d, csValue.GetLength()); 
 
  // if we failed, note it, and leave return errID
  if (lRetCode != ERROR_SUCCESS) { 
    return lRetCode ; 
    } 
  return lRetCode;
}

LONG CReg::GetKey(CString csPath, CString csName,int &nValue)
{
	CString csValue;
	long lret=GetKey(csPath,  csName, csValue);
	nValue=atoi(csValue);
	return lret;

}
LONG CReg::GetKey(CString csPath, CString csName, CString &csValue)
{
   HKEY  hKey1; 
  DWORD  dwDisposition; 
  LONG   lRetCode; 
  CString cstemp="SOFTWARE\\";
  cstemp.Format("SOFTWARE\\%s",csPath);
  // try to create the .REG file key 
  lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE,cstemp,0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey1, &dwDisposition); 

	
  // if we failed, note it, and leave return errID you can use FormatMessage ReadIt
  if (lRetCode != ERROR_SUCCESS){ 
      return lRetCode; 
    }
  //读取值
  unsigned long lBufferLength;  
  char buf[256];
  lBufferLength=255;
  //lRetCode = RegQueryValueEx ( hKey1, csName,  0,NULL, (BYTE *)csValue.GetBufferSetLength(100),&lBufferLength); 
  lRetCode = RegQueryValueEx ( hKey1, csName,  0,NULL, (BYTE *)buf,&lBufferLength); 
if (lRetCode!=0)
{
	lBufferLength=0;
}
  csValue.GetBufferSetLength(lBufferLength);
  buf[lBufferLength]='\0';
  csValue=buf;

  // if we failed, note it, and leave return errID you can use FormatMessage ReadIt
  if (lRetCode != ERROR_SUCCESS) { 
    return  lRetCode; 
    } 
  return lRetCode;
}
long CReg::SetKey(CString csPath,CString csName,int nValue)
{
	CString csValue;
	csValue.Format("%d",nValue);
	return SetKey( csPath, csName,csValue);
	
}

⌨️ 快捷键说明

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