win32 您所在的位置:网站首页 vc编写注册表 win32

win32

2024-07-12 01:12| 来源: 网络整理| 查看: 265

文章目录 1.32访问64位和64位访问32位2.在Qt中qsetting的使用3.总结

1.32访问64位和64位访问32位

32位的应用程序想访问64位的注册表视图的标志是KEY_WOW64_64KEY,该标志的值是0x0100。64位的应用程序想访问32位的注册表视图的标志是KEY_WOW64_32KEY。以上两个标志可以在RegCreateKeyEx()函数、RegDeleteKeyEx()函数和RegOpenKeyEx()函数中指定。

LONG lReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\***", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);

范例,32位读取64位注册表。

//写注册表信息 static bool SetRegValue(const std::string& item, const std::string& value) { HKEY hkey = nullptr; LSTATUS res = ::RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Corel\\Setup\\CorelDRAW Graphics Suite 2019", 0, KEY_WRITE | KEY_WOW64_64KEY, &hkey); if (res != ERROR_SUCCESS) { res = ::RegCreateKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Corel\\Setup\\CorelDRAW Graphics Suite 2019", &hkey); } if (res != ERROR_SUCCESS) { if (hkey != nullptr) { ::RegCloseKey(hkey); hkey = nullptr; } return false; } res = ::RegSetValueExA(hkey, item.c_str(), 0, REG_SZ, (BYTE*)value.c_str(), value.length()); if (res != ERROR_SUCCESS) { return false; } return true; } //读取注册表信息 static std::string GetRegValue(const std::string& item) { HKEY hkey = nullptr; LSTATUS res = ::RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Corel\\Setup\\CorelDRAW Graphics Suite 2019", 0, KEY_READ | KEY_WOW64_64KEY, &hkey); if (res != ERROR_SUCCESS) { if (hkey != nullptr) { ::RegCloseKey(hkey); hkey = nullptr; } return ""; } DWORD type = REG_SZ; DWORD size = 0; res = ::RegQueryValueExA(hkey, item.c_str(), 0, &type, nullptr, &size); if (res != ERROR_SUCCESS || size return ""; } return std::string(value_data.begin(), value_data.end()); } 2.在Qt中qsetting的使用

32程序访问64位注册表,必须使用QSettings::Registry64Format标志,而不能简单使用本地标志QSettings::NativeFormat。

QString regPos = QString::fromLocal8Bit("HKEY_LOCAL_MACHINE/SOFTWARE/Corel/Setup/CorelDRAW Graphics Suite 2019"); regPos.replace("/", "\\"); QSettings tQSettings(regPos, QSettings::Registry64Format);//32程序访问64位注册表-必须采用这种方式 QString destination = tQSettings.value("Destination").toString(); 3.总结

注册表,是windows系统保存配置的地方,64位系统为了兼容32位,又做了许多兼容的设计,才出现了这些过渡的配置。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有