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

📄 reg.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
字号:
// reg.cpp

#include <windows.h>
#include "msc.h"
#include "reg.h"

// szValueName 偵 "" 傪巜掕偟偨傜丄"(昗弨)" 偺抣傪庢摼/弌椡



//////////////////////////////
//          ANSI斉          //
//////////////////////////////



// 儗僕僗僩儕偐傜壙傪庢摼偡傞乮ANSI斉乯
// dwDataSizeMax 偼僶僀僩悢
// dwDataTypeRequired 埲崀偵 0 傪巜掕偟偨傜丄抣偑懚嵼偡傞偐傪妋擣偟偰廔椆
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int GetRegInfoA ( HKEY hKey, const char *szSubkey, const char *szValueName, unsigned long dwDataTypeRequired, void *pData, unsigned long dwDataSizeMax ) {

   int nResult ;
   HKEY hRegKey ;
   unsigned long dwDataType = dwDataTypeRequired ;

   nResult = RegOpenKeyExA ( hKey, szSubkey, 0, KEY_READ, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegQueryValueExA ( hRegKey, szValueName, NULL, & dwDataType, (unsigned char*) pData, & dwDataSizeMax ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   if ( dwDataTypeRequired && dwDataType != dwDataTypeRequired ) return 1 ;
   return 0 ;
}



// 儗僕僗僩儕傊壙傪弌椡偡傞乮ANSI斉乯
// dwDataSize 偼僶僀僩悢
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int SetRegInfoA ( HKEY hKey, const char *szSubkey, const char *szValueName, unsigned long dwDataType, const void *pData, unsigned long dwDataSize ) {

   int nResult ;
   HKEY hRegKey ;

   nResult = RegCreateKeyExA ( hKey, szSubkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, & hRegKey, NULL ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegSetValueExA ( hRegKey, szValueName, 0, dwDataType, (const unsigned char*) pData, dwDataSize ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



// 儗僕僗僩儕偐傜暥帤楍傪庢摼偡傞乮ANSI斉乯
// dwDataSizeMax 偼暥帤悢
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int GetRegStringA ( HKEY hKey, const char *szSubkey, const char *szValueName, char *pData, unsigned long dwDataSizeMax ) {
   return GetRegInfoA ( hKey, szSubkey, szValueName, REG_SZ, pData, dwDataSizeMax * sizeof(char) ) ;
}



// 儗僕僗僩儕傊暥帤楍傪弌椡偡傞乮ANSI斉乯
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int SetRegStringA ( HKEY hKey, const char *szSubkey, const char *szValueName, const char *pData ) {
   return SetRegInfoA ( hKey, szSubkey, szValueName, REG_SZ, pData, (unsigned long) ( strlen ( pData ) + 1 ) * sizeof(char) ) ;
}



// 儗僕僗僩儕偺僄儞僩儕乕傪嶍彍偡傞乮ANSI斉乯
// szValueName 偑 NULL 側傜 僉乕偦偺傕偺傪嶍彍
// 偨偩偟丄僒僽僉乕偑懚嵼偡傟偽僉乕傪嶍彍偱偒側偄
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int DeleteRegInfoA ( HKEY hKey, const char *szSubkey, const char *szValueName ) {

   int nResult ;
   HKEY hRegKey ;

   nResult = RegOpenKeyExA ( hKey, szSubkey, 0, KEY_WRITE | KEY_QUERY_VALUE, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   if ( szValueName ) nResult = RegDeleteValueA ( hRegKey, szValueName ) ;
   else {
      // 95宯偱偼丄僒僽僉乕偑懚嵼偟偰傕嶍彍偟偰偟傑偆偺偱丄帠慜偵専嵏
      unsigned long dwSubkeyCount ;
      nResult = RegQueryInfoKey ( hRegKey, NULL, NULL, NULL, & dwSubkeyCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ;
      if ( nResult == ERROR_SUCCESS && ! dwSubkeyCount ) nResult = RegDeleteKeyA ( hKey, szSubkey ) ;
      else                                               nResult = ERROR_ACCESS_DENIED ;
   }

   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



// 儗僕僗僩儕偵傾僋僙僗壜擻偐傪庢摼偡傞乮ANSI斉乯
// dwAccessMask 偵偼 KEY_ALL_ACCESS, KEY_WRITE, KEY_READ 摍傪巜掕
// 傾僋僙僗壜擻側傜 0 埲奜傪丄晄壜擻側傜 0 傪曉偡
int IsRegKeyAccessibleA ( HKEY hKey, const char *szSubkey, REGSAM dwAccessMask ) {

   int nResult ;
   HKEY hRegKey ;

   nResult = RegOpenKeyExA ( hKey, szSubkey, 0, dwAccessMask, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 0 ;
   RegCloseKey ( hRegKey ) ;

   return 1 ;
}



// 僒僽僉乕傪楍嫇偡傞乮ANSI斉乯
// nNumber 偵偼 0 偐傜弴偵斣崋傪巜掕
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int EnumRegSubkeyA ( HKEY hKey, const char *szSubkey, int nNumber, char *szName ) {

   int nResult ;
   HKEY hRegKey ;
   unsigned long dwLength = MAX_PATH ;

   nResult = RegOpenKeyExA ( hKey, szSubkey, 0, KEY_READ, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegEnumKeyExA ( hRegKey, nNumber, szName, & dwLength, NULL, NULL, NULL, NULL ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



// 僄儞僩儕乕傪楍嫇偡傞乮ANSI斉乯
// nNumber 偵偼 0 偐傜弴偵斣崋傪巜掕
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int EnumRegValueA ( HKEY hKey, const char *szSubkey, int nNumber, char *szName ) {

   int nResult ;
   HKEY hRegKey ;
   unsigned long dwLength = MAX_PATH ;

   nResult = RegOpenKeyExA ( hKey, szSubkey, 0, KEY_READ, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegEnumValueA ( hRegKey, nNumber, szName, & dwLength, NULL, NULL, NULL, NULL ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



//////////////////////////////
//         UNICODE斉        //
//////////////////////////////



// 儗僕僗僩儕偐傜壙傪庢摼偡傞乮UNICODE斉乯
// dwDataSizeMax 偼僶僀僩悢
// dwDataTypeRequired 埲崀偵 0 傪巜掕偟偨傜丄抣偑懚嵼偡傞偐傪妋擣偟偰廔椆
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int GetRegInfoW ( HKEY hKey, const wchar_t *szSubkey, const wchar_t *szValueName, unsigned long dwDataTypeRequired, void *pData, unsigned long dwDataSizeMax ) {

   int nResult ;
   HKEY hRegKey ;
   unsigned long dwDataType = dwDataTypeRequired ;

   nResult = RegOpenKeyExW ( hKey, szSubkey, 0, KEY_READ, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegQueryValueExW ( hRegKey, szValueName, NULL, & dwDataType, (unsigned char*) pData, & dwDataSizeMax ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   if ( dwDataTypeRequired && dwDataType != dwDataTypeRequired ) return 1 ;
   return 0 ;
}



// 儗僕僗僩儕傊壙傪弌椡偡傞乮UNICODE斉乯
// dwDataSize 偼僶僀僩悢
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int SetRegInfoW ( HKEY hKey, const wchar_t *szSubkey, const wchar_t *szValueName, unsigned long dwDataType, const void *pData, unsigned long dwDataSize ) {

   int nResult ;
   HKEY hRegKey ;

   nResult = RegCreateKeyExW ( hKey, szSubkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, & hRegKey, NULL ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegSetValueExW ( hRegKey, szValueName, 0, dwDataType, (const unsigned char*) pData, dwDataSize ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



// 儗僕僗僩儕偐傜暥帤楍傪庢摼偡傞乮UNICODE斉乯
// dwDataSizeMax 偼暥帤悢
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int GetRegStringW ( HKEY hKey, const wchar_t *szSubkey, const wchar_t *szValueName, wchar_t *pData, unsigned long dwDataSizeMax ) {
   return GetRegInfoW ( hKey, szSubkey, szValueName, REG_SZ, pData, dwDataSizeMax * sizeof(wchar_t) ) ;
}



// 儗僕僗僩儕傊暥帤楍傪弌椡偡傞乮UNICODE斉乯
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int SetRegStringW ( HKEY hKey, const wchar_t *szSubkey, const wchar_t *szValueName, const wchar_t *pData ) {
   return SetRegInfoW ( hKey, szSubkey, szValueName, REG_SZ, pData, (unsigned long) ( wcslen ( pData ) + 1 ) * sizeof(wchar_t) ) ;
}



// 儗僕僗僩儕偺僄儞僩儕乕傪嶍彍偡傞乮UNICODE斉乯
// szValueName 偑 NULL 側傜 僉乕偦偺傕偺傪嶍彍
// 偨偩偟丄僒僽僉乕偑懚嵼偡傟偽僉乕傪嶍彍偱偒側偄
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int DeleteRegInfoW ( HKEY hKey, const wchar_t *szSubkey, const wchar_t *szValueName ) {

   int nResult ;
   HKEY hRegKey ;

   nResult = RegOpenKeyExW ( hKey, szSubkey, 0, KEY_WRITE | KEY_QUERY_VALUE, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   if ( szValueName ) nResult = RegDeleteValueW ( hRegKey, szValueName ) ;
   else {
      // 95宯偱偼丄僒僽僉乕偑懚嵼偟偰傕嶍彍偟偰偟傑偆偺偱丄帠慜偵専嵏
      unsigned long dwSubkeyCount ;
      nResult = RegQueryInfoKey ( hRegKey, NULL, NULL, NULL, & dwSubkeyCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ;
      if ( nResult == ERROR_SUCCESS && ! dwSubkeyCount ) nResult = RegDeleteKeyW ( hKey, szSubkey ) ;
      else                                               nResult = ERROR_ACCESS_DENIED ;
   }

   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



// 儗僕僗僩儕偵傾僋僙僗壜擻偐傪庢摼偡傞乮UNICODE斉乯
// dwAccessMask 偵偼 KEY_ALL_ACCESS, KEY_WRITE, KEY_READ 摍傪巜掕
// 傾僋僙僗壜擻側傜 0 埲奜傪丄晄壜擻側傜 0 傪曉偡
int IsRegKeyAccessibleW ( HKEY hKey, const wchar_t *szSubkey, REGSAM dwAccessMask ) {

   int nResult ;
   HKEY hRegKey ;

   nResult = RegOpenKeyExW ( hKey, szSubkey, 0, dwAccessMask, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 0 ;
   RegCloseKey ( hRegKey ) ;

   return 1 ;
}



// 僒僽僉乕傪楍嫇乮UNICODE斉乯
// nNumber 偵偼 0 偐傜弴偵斣崋傪巜掕
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int EnumRegSubkeyW ( HKEY hKey, const wchar_t *szSubkey, int nNumber, wchar_t *szName ) {

   int nResult ;
   HKEY hRegKey ;
   unsigned long dwLength = MAX_PATH ;

   nResult = RegOpenKeyExW ( hKey, szSubkey, 0, KEY_READ, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegEnumKeyExW ( hRegKey, nNumber, szName, & dwLength, NULL, NULL, NULL, NULL ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



// 僄儞僩儕乕傪楍嫇偡傞乮UNICODE斉乯
// nNumber 偵偼 0 偐傜弴偵斣崋傪巜掕
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int EnumRegValueW ( HKEY hKey, const wchar_t *szSubkey, int nNumber, wchar_t *szName ) {

   int nResult ;
   HKEY hRegKey ;
   unsigned long dwLength = MAX_PATH ;

   nResult = RegOpenKeyExW ( hKey, szSubkey, 0, KEY_READ, & hRegKey ) ;
   if ( nResult != ERROR_SUCCESS ) return 1 ;

   nResult = RegEnumValueW ( hRegKey, nNumber, szName, & dwLength, NULL, NULL, NULL, NULL ) ;
   RegCloseKey ( hRegKey ) ;

   if ( nResult != ERROR_SUCCESS ) return 1 ;
   return 0 ;
}



⌨️ 快捷键说明

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