|
[code]const TCHAR *
RegGetString(HKEY hKey, const TCHAR *subKey, const TCHAR *name)
{
HKEY hSubKey;
DWORD type;
static TCHAR value[4096];
DWORD size = sizeof(value);
value[0] = _T('\0');
if ( RegOpenKeyEx(hKey, subKey, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS )
{
if ( (RegQueryValueEx(hSubKey, name, 0, &type, (LPBYTE)value, &size) != ERROR_SUCCESS) ||
(type != REG_SZ) )
value[0] = _T('\0');
RegCloseKey(hSubKey);
}
return value;
}
int
RegPutString(HKEY hKey, const TCHAR *subKey, const TCHAR *name, const TCHAR *value)
{
HKEY hSubKey;
DWORD disp;
int retval = 0;
if ( RegCreateKeyEx(hKey, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &disp) == ERROR_SUCCESS )
{
if ( RegSetValueEx(hSubKey, name, 0, REG_SZ, (LPBYTE)value, (_tcslen(value) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS )
retval = 1;
RegCloseKey(hSubKey);
}
return retval;
}
int
RegGetInt(HKEY hKey, const TCHAR *subKey, const TCHAR *name)
{
HKEY hSubKey;
DWORD type;
DWORD value = 0;
DWORD size = sizeof(value);
if ( RegOpenKeyEx(hKey, subKey, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS )
{
if ( (RegQueryValueEx(hSubKey, name, 0, &type, (LPBYTE)&value, &size) != ERROR_SUCCESS) ||
(type != REG_DWORD) )
value = 0;
RegCloseKey(hSubKey);
}
return value;
}
int
RegPutInt(HKEY hKey, const TCHAR *subKey, const TCHAR *name, int value)
{
HKEY hSubKey;
DWORD disp;
int retval = 0;
if ( RegCreateKeyEx(hKey, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &disp) == ERROR_SUCCESS )
{
if ( RegSetValueEx(hSubKey, name, 0, REG_DWORD, (LPBYTE)&value, sizeof(value)) == ERROR_SUCCESS )
retval = 1;
RegCloseKey(hSubKey);
}
return retval;
}
int RegPut_B (HKEY hKey,const TCHAR *subKey,const TCHAR *name,BYTE ReSetContent_B[65536])
{
//设置二进制值函数
int i=0; //操作结果:1==succeed
if(RegOpenKeyEx(hKey,subKey,0,KEY_WRITE,&hKey)==ERROR_SUCCESS)
{
i=1;
if(RegSetValueEx(hKey,name,NULL,REG_BINARY,ReSetContent_B,65536)!=ERROR_SUCCESS)
{
//AfxMessageBox("错误:无法设置有关的注册表信息");
i=0;
}
RegCloseKey(hKey);
}
else
{
//AfxMessageBox("错误:无法查询有关的注册表信息");
i=0;
}
return i;
}
int RegGet_B(HKEY hKey, const TCHAR *subKey, const TCHAR *name, BYTE value_B[65536])
{
HKEY hSubKey;
DWORD type;
int rt=0; //操作结果:1==succeed
DWORD size = 65536; //buffsize
if ( RegOpenKeyEx(hKey, subKey, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS )
{
rt = 1;
if ( (RegQueryValueEx(hSubKey, name, 0, &type, (LPBYTE)value_B, &size) != ERROR_SUCCESS) ||
(type != REG_BINARY) )
rt = 0;
RegCloseKey(hSubKey);
}
return rt;
}[/code] |
|