【原创】注册表的读写API(windows)

来源:互联网 发布:英文面试常见问题知乎 编辑:程序博客网 时间:2024/05/21 09:41

/// 根键值

HKEY m_base;

m_base = HKEY_CURRENT_USER;


/// 注册表位置

wxString m_path;

m_path = wxT("Software\\ThpClient\\DirPath\\CalcDllPath");


/// 注册表键值位置

std::string m_key;

m_key = "myselfValue";


/// 需要修改的键值

std::string m_value = "http://www.baidu.com";


/// 键值句柄,存储

HKEY m_hKey;


/// 错误代号

LONG LastError;


/// 打开注册表的类型

DWORD disp= REG_OPENED_EXISTING_KEY;


/// 创建注册表句柄

RegCreateKeyEx(m_base, m_path, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &m_hKey, &disp))!=ERROR_SUCCESS)


/// 写入键值

RegSetValueExA(m_hKey, m_key.c_str(), 0, REG_SZ, (const BYTE*)m_value.c_str(),m_value.size())==ERROR_SUCCESS)


/// 读取键值

char m_readvalue[512] = {0};

DWORD m_typeword;

DWORD m_valuelength;

RegQueryValueExA(m_hKey, m_key.c_str(), 0, &m_typeword, (LPBYTE)m_readvalue,&m_valuelength);


/// 关闭注册表句柄
LastError = RegCloseKey(m_hKey);
原创粉丝点击