c++ 读写注册表
void RegUpdate(HKEY hRootKey,LPCSTR szSubKey,LPCSTR szValueName,LPCSTR szValue) { HKEY hKey; LONG rc; int nFile; rc = RegCreateKeyEx(hRootKey, szSubKey, NULL, NULL, 0, KEY_WRITE, NULL, &hKey, NULL); if(rc != ERROR_SUCCESS) return; nFile = strlen(szValue); RegSetValueEx(hKey, szValueName, NULL, REG_SZ, (LPBYTE)szValue, nFile); RegCloseKey(hKey); } string RegGet(HKEY hRootKey,LPCSTR szSubKey,LPCSTR szValueName) { HKEY hKey; LONG rc; DWORD dwType; char szValue[1024]; DWORD dwSize; rc = RegOpenKey(hRootKey, szSubKey, &hKey); if(rc != ERROR_SUCCESS) return FALSE; rc = RegQueryValueEx(hKey, szValueName, NULL, &dwType, (LPBYTE)szValue, &dwSize); if(rc == ERROR_SUCCESS && dwType == REG_SZ) { RegCloseKey(hKey); return (string)szValue; } RegCloseKey(hKey); return NULL; }
桂棹兮兰桨,击空明兮溯流光。