//获取注册表值 CString GetRegValue(HKEY key, LPCTSTR lpszKeyName, LPCTSTR lpszValueName) { CString strReturnValue = _T(""); if (key == NULL || lpszKeyName == NULL || lpszValueName == NULL) { AfxMessageBox(_T("读取注册表的参数不能为空")); return strReturnValue; } CRegKey reg; LONG lOpenErrorCode = reg.Open(key,lpszKeyName,KEY_READ); if (lOpenErrorCode != ERROR_SUCCESS) { AfxMessageBox(_T("打开注册表键失败")); return strReturnValue; } LONG lReadErrorCode = 0; const int BUFFER_SIZE = MAX_PATH; ULONG iLength = BUFFER_SIZE; lReadErrorCode = reg.QueryStringValue(lpszValueName, strReturnValue.GetBuffer(BUFFER_SIZE), &iLength); strReturnValue.ReleaseBuffer(); if (lReadErrorCode != ERROR_SUCCESS) { AfxMessageBox(_T("读取注册表键值失败")); return strReturnValue; } reg.Close(); return strReturnValue; }
读取注册表值
最新推荐文章于 2023-08-28 17:23:09 发布
本文介绍了一个使用C++实现的从Windows注册表中读取特定键值的方法。该函数通过提供注册表根键、子键名称及键值名称来定位并返回相应的字符串类型值。如果过程中出现错误,如参数为空、打开或读取键失败等,函数将显示错误消息并返回空字符串。
1779

被折叠的 条评论
为什么被折叠?



