c++ - RegSetKeyValueA 函数是否有任何向后兼容的替代方法?

标签 c++ winapi windows-xp backwards-compatibility

在我的应用程序中,我使用 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替换为MyRegSetKeyValueWA 版本可以这样做,但需要了解 A 版本将字符串参数转换为 unicode,然后调用 W 版本。所以最好直接调用 W 版本

关于c++ - RegSetKeyValueA 函数是否有任何向后兼容的替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55776182/

相关文章:

用于输出通用结构的 C++ 函数

c - 未定义对 'SetCurrentConsoleFontEx' 的引用?

delphi - Wininet InternetSetStatusCallback 不起作用

windows-xp - inno setup.exe 在 Windows XP 上因浮点除以零而失败

C++ 库路径包含

c++ - 无法使用 clang 交叉编译为 SPARC

python - 在没有模板的情况下访问构造函数中的重写字段

c++ - 阻止编译器为导入的函数生成包装器

linux - 使用 TeamViewer 在 Windows xp 上远程安装 Linux

c# - 以 Windows XP 为目标平台的 VS 2015 中推荐的内容