在我的应用程序中,我使用 RegSetKeyValueA在注册表中存储一些激活 key 。
阻止我的应用程序向后兼容 Windows XP 的唯一瓶颈是 RegSetKeyValueA功能。
有什么办法可以解决这个问题吗?
最佳答案
RegSetKeyValueW
功能可以通过使用轻松实现 RegSetValueExW
从 Windows 2000 就存在
LSTATUS MyRegSetKeyValueW(
HKEY hKey,
LPCWSTR lpSubKey,
LPCWSTR lpValueName,
DWORD dwType,
LPCVOID lpData,
DWORD cbData
)
{
LSTATUS s;
if (lpSubKey && *lpSubKey)
{
s = RegCreateKeyExW(hKey, lpSubKey, 0, 0, 0, KEY_SET_VALUE, 0, &hKey, 0);
if (s != NOERROR)
{
return s;
}
}
s = RegSetValueExW(hKey, lpValueName, 0, dwType,
static_cast<PBYTE>(const_cast<void*>(lpData)), cbData);
if (lpSubKey && *lpSubKey)
{
RegCloseKey(hKey);
}
return s;
}
并将自身代码中的RegSetKeyValueW
替换为MyRegSetKeyValueW
。 A 版本可以这样做,但需要了解 A 版本将字符串参数转换为 unicode,然后调用 W 版本。所以最好直接调用 W 版本
关于c++ - RegSetKeyValueA 函数是否有任何向后兼容的替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55776182/