找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 157|回复: 0

[每日一码] ARX注册表操作函数集

[复制链接]

1

主题

0

回帖

55

积分

管理员

积分
55
发表于 2024-3-14 20:31:54 | 显示全部楼层 |阅读模式
  1. onst TCHAR *
  2.         RegGetString(HKEY hKey, const TCHAR *subKey, const TCHAR *name)
  3. {
  4.         HKEY hSubKey;
  5.         DWORD type;
  6.         static TCHAR value[4096];
  7.         DWORD size = sizeof(value);
  8.         value[0] = 采用T('\0');
  9.         if ( RegOpenKeyEx(hKey, subKey, 0, KEY采用QUERY采用VALUE, &hSubKey) == ERROR采用SUCCESS )
  10.         {
  11.                 if ( (RegQueryValueEx(hSubKey, name, 0, &type, (LPBYTE)value, &size) != ERROR采用SUCCESS) ||
  12.                         (type != REG采用SZ) )
  13.                         value[0] = 采用T('\0');
  14.                 RegCloseKey(hSubKey);
  15.         }
  16.         return value;
  17. }
  18. int
  19.         RegPutString(HKEY hKey, const TCHAR *subKey, const TCHAR *name, const TCHAR *value)
  20. {
  21.         HKEY hSubKey;
  22.         DWORD disp;
  23.         int retval = 0;
  24.         if ( RegCreateKeyEx(hKey, subKey, 0, NULL, REG采用OPTION采用NON采用VOLATILE, KEY采用WRITE, NULL, &hSubKey, &disp) == ERROR采用SUCCESS )
  25.         {
  26.                 if ( RegSetValueEx(hSubKey, name, 0, REG采用SZ, (LPBYTE)value, (采用tcslen(value) + 1) * sizeof(TCHAR)) == ERROR采用SUCCESS )
  27.                         retval = 1;
  28.                 RegCloseKey(hSubKey);
  29.         }
  30.         return retval;
  31. }
  32. int
  33.         RegGetInt(HKEY hKey, const TCHAR *subKey, const TCHAR *name)
  34. {
  35.         HKEY hSubKey;
  36.         DWORD type;
  37.         DWORD value = 0;
  38.         DWORD size = sizeof(value);
  39.         if ( RegOpenKeyEx(hKey, subKey, 0, KEY采用QUERY采用VALUE, &hSubKey) == ERROR采用SUCCESS )
  40.         {
  41.                 if ( (RegQueryValueEx(hSubKey, name, 0, &type, (LPBYTE)&value, &size) != ERROR采用SUCCESS) ||
  42.                         (type != REG采用DWORD) )
  43.                         value = 0;
  44.                 RegCloseKey(hSubKey);
  45.         }
  46.         return value;
  47. }
  48. int
  49.         RegPutInt(HKEY hKey, const TCHAR *subKey, const TCHAR *name, int value)
  50. {
  51.         HKEY hSubKey;
  52.         DWORD disp;
  53.         int retval = 0;
  54.         if ( RegCreateKeyEx(hKey, subKey, 0, NULL, REG采用OPTION采用NON采用VOLATILE, KEY采用WRITE, NULL, &hSubKey, &disp) == ERROR采用SUCCESS )
  55.         {
  56.                 if ( RegSetValueEx(hSubKey, name, 0, REG采用DWORD, (LPBYTE)&value, sizeof(value)) == ERROR采用SUCCESS )
  57.                         retval = 1;
  58.                 RegCloseKey(hSubKey);
  59.         }
  60.         return retval;
  61. }
  62. int RegPut采用B (HKEY hKey,const TCHAR  *subKey,const TCHAR  *name,BYTE ReSetContent采用B[65536])
  63. {
  64.         //设置二进制值函数
  65.         int i=0; //操作结果:1==succeed
  66.         if(RegOpenKeyEx(hKey,subKey,0,KEY采用WRITE,&hKey)==ERROR采用SUCCESS)
  67.         {
  68.                 i=1;
  69.                 if(RegSetValueEx(hKey,name,NULL,REG采用BINARY,ReSetContent采用B,65536)!=ERROR采用SUCCESS)
  70.                 {
  71.                         //AfxMessageBox("错误:无法设置有关的注册表信息");
  72.                         i=0;
  73.                 }
  74.                 RegCloseKey(hKey);
  75.         }
  76.         else
  77.         {
  78.                 //AfxMessageBox("错误:无法查询有关的注册表信息");
  79.                 i=0;
  80.         }
  81.         return i;
  82. }
  83. int RegGet采用B(HKEY hKey, const TCHAR *subKey, const TCHAR *name, BYTE value采用B[65536])
  84. {
  85.         HKEY hSubKey;
  86.         DWORD type;
  87.         int rt=0; //操作结果:1==succeed
  88.         DWORD size = 65536; //buffsize
  89.         if ( RegOpenKeyEx(hKey, subKey, 0, KEY采用QUERY采用VALUE, &hSubKey) == ERROR采用SUCCESS )
  90.         {
  91.                 rt = 1;
  92.                 if ( (RegQueryValueEx(hSubKey, name, 0, &type, (LPBYTE)value采用B, &size) != ERROR采用SUCCESS) ||
  93.                         (type != REG采用BINARY) )
  94.                         rt = 0;
  95.                 RegCloseKey(hSubKey);
  96.         }
  97.         return rt;
  98. }
复制代码

 

 

 

 

[每日一码] ARX注册表操作函数集
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-2-6 02:49 , Processed in 0.073820 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表