在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);