读取注册表值

来源:互联网 发布:matlab优化工具箱求解 编辑:程序博客网 时间:2024/04/30 09:11
//获取注册表值 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; }
原创粉丝点击