//读注册表
std::wstring CRegInfo::GetRegValue(HKEY hKeyType,DWORD dwType,LPCTSTR lpPath,LPCTSTR lpName)
{
HKEY hKEY;
DWORD dataSize = MAX_PATH;
char data[MAX_PATH];
std::string strValue("");
if (RegOpenKeyEx(hKeyType,lpPath,NULL,KEY_READ,&hKEY) == ERROR_SUCCESS) //如果无法打开hKEY,则中止程序的执行
{
long lRet = RegQueryValueEx(hKEY,lpName,&dwType,(LPBYTE)data,&dataSize);
if (lRet == ERROR_SUCCESS)
{
for (int i = 0; i < (int)dataSize; i++)
{
strValue = strValue + data[i];
}
}
RegCloseKey(hKEY); // 程序结束前要关闭已经打开的 hKEY。
}
else
{
RegCreateKeyEx(hKeyType,(LPCTSTR)lpPath,KEY_WRITE,&hKEY,NULL);
RegCloseKey(hKEY); // 程序结束前要关闭已经打开的 hKEY。
}
std::wstring wstrValue((wchar_t*)strValue.data(),strValue.length() / 2);
return wstrValue;
}
eg:
std::wstring strValue;
strValue = GetRegValue(HKEY_LOCAL_MACHINE,REG_SZ,L"SoftWareMicrosoftWindowsCurrentVersionApp PathsWebService",L"WebServiceIP");
//写注册表
void WriteRegedit(LPCTSTR m_path,LPCTSTR m_name,CString strParame)
{
HKEY hKEY;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,m_path,则中止程序的执行
{
RegSetValueEx(hKEY,m_name,(BYTE*)strParame.GetBuffer(strParame.GetLength()),2 * strParame.GetLength());
strParame.ReleaseBuffer();
RegCloseKey(hKEY);
}
else
{
RegCreateKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)m_path,NULL);
RegSetValueEx(hKEY,2 * strParame.GetLength());
strParame.ReleaseBuffer();
RegCloseKey(hKEY);
}
}
eg:
m_RegInfo.WriteRegedit(_T(“SoftWareMicrosoftWindowsCurrentVersionApp PathsWebService”),_T(“WebServiceIP”),_T(“192.168.0.0”));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。