VC 注册表读写
BYTE Vals[256]; HKEY hKEY; //打开注册表,判断注册表项是否存在 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WeldTech\\AirCondition\\"), 0, KEY_READ|KEY_WRITE, &hKEY) != ERROR_SUCCESS) { //不存在,创建注册表项 if(::RegCreateKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WeldTech\\AirCondition\\"), &hKEY) != ERROR_SUCCESS) { } } ::RegSetValueEx( hKEY, _T("SavePath"), 0, REG_SZ, (LPBYTE)(LPCTSTR)g_saveDataPath, 256 ); //s设置注册表的键和值,相当于创建了键 ::RegCloseKey(hKEY); //查询注册表 CString g_saveDataPath ; BYTE Vals[256]; HKEY hKEY; DWORD type_1 = REG_SZ; DWORD cbData_1 = 256; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WeldTech\\AirCondition\\"), 0, KEY_READ|KEY_WRITE, &hKEY) == ERROR_SUCCESS) { if(::RegQueryValueEx(hKEY, _T("SavePath"), NULL,&type_1,(BYTE*)Vals, &cbData_1)==ERROR_SUCCESS) { CString strRead; strRead.Format(_T("%s"), Vals); strRead.Trim(); g_saveDataPath = strRead; } } ::RegCloseKey(hKEY);