c++当中的注册表操作

在c++当中 注册表操作为了存储某些软件的初始化信息。其中存储了某些键值供读取。

1.在某些系统里存储于winin文件中。某些系统写入注册表

操作写入:

   SetRegistryKey(_T("bobbypractise675476476486457647647"));   //设计注册表单名称

   WriteProfileString("bobby's practise","admin","bobby");
操作读取:

   CString str;
   str = GetProfileString("bobby's practise","admin");
   AfxMessageBox(str);

2.注册表的写入读取等操作:

 写操作:

 

    HKEY hKey;
    RegCreateKey(HKEY_LOCAL_MACHINE ,_T("Software\\dafdafdadfdaffdafdagdafdafdaf\\admin"),&hKey);
    RegSetValue(hKey,NULL,REG_SZ,"shuju",strlen("shuju"));             //set the regedit value
    RegCloseKey(hKey);

读操作:

    LONG lValue;
    RegQueryValue(HKEY_LOCAL_MACHINE ,_T("Software\\dafdafdadfdaffdafdagdafdafdaf\\admin"),NULL, &lValue);
    char *pBuf = new char[lValue];
    RegQueryValue(HKEY_LOCAL_MACHINE ,_T("Software\\dafdafdadfdaffdafdagdafdafdaf\\admin"),pBuf, &lValue);
    MessageBox(pBuf);

上述两例均是字符串类型数据。

整形改用 RegSetValueEx

    HKEY hKey;
    DWORD dwAge;
    RegCreateKey(HKEY_LOCAL_MACHINE ,_T("Software\\dafdafdadfdaffdafdagdafdafdaf\\admin"),&hKey);
    RegSetValue(hKey,NULL,REG_SZ,"shuju",strlen("shuju"));             //set the regedit value
    RegSetValueEx(hKey,"age",0,REG_DWORD,(CONST BYTE*)&dwAge,4);
    RegCloseKey(hKey);

打开操作:

   

   HKEY hKey;
   RegOpenKey(HKEY_LOCAL_MACHINE,_T("Software\\dafdafdadfdaffdafdagdafdafdaf\\admin"),&hKey);
   DWORD dwType;
   DWORD dwValue;
   DWORD dwAge;
   RegQueryValueEx(hKey,"age",0,&dwType,(LPBYTE)&dwAge,&dwValue);
   CString str;
   str.Format("age = %d",dwAge);
   MessageBox(str);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值