void CSLtestDlg::OnButton3()
{
// TODO: Add your control notification handler code here
//读取注册表中的值
HKEY hKey;
//DWORD dwType;
TCHAR szNameServer[256];
//LPBYTE
DWORD dwDataSize=256;
//LPDWORD
DWORD dwType;
LONG retval=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\services\\umbus",0,KEY_QUERY_VALUE,&hKey);
if(retval==ERROR_SUCCESS)
//若调用成功
{
RegQueryValueEx(hKey,_T("DisplayName"),NULL,&dwType,(LPBYTE)szNameServer,&dwDataSize);
//获取值
}
AfxMessageBox((CString)szNameServer);
//创建键值
LONG retva=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\services\\gogo",0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, &hKey,NULL);
if(retval==ERROR_SUCCESS)
{
if(RegSetValueEx(hKey,_T("HAPPY"),0,dwType,NULL,NULL)==ERROR_SUCCESS)
//写入数据
{
AfxMessageBox("写入成功");
}
else
{
AfxMessageBox("写入失败");
}
}
RegCloseKey(hKey);
}
出现了写入失败,也不知道怎么回事??