
正文
c++ 读写注册表
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
void RegUpdate(HKEY hRootKey,LPCSTR szSubKey,LPCSTR szValueName,LPCSTR szValue)
{
HKEY hKey;
LONG rc;
int nFile;
rc = RegCreateKeyEx(hRootKey, szSubKey, NULL, NULL, , 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[];
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;
}








