c ++ get注册表项只返回一个char

时间:2010-12-19 13:15:25

标签: c++ registry

我正在尝试检索密钥的值,但我只获取值的第一个字符.. 有人可以帮忙吗?

我的代码:

void dealWithRegistry()
{
    HKEY regkey1;
    char data[100];
    DWORD datasize = sizeof (data) / sizeof (char);
    LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, &regkey1);
    if (rc != ERROR_SUCCESS)
    {
        cout << "there was a problem openning" << endl;
    }
    else
    {
        rc = RegGetValue (regkey1, NULL, L"AppData", RRF_RT_REG_SZ, NULL, (void*) data, &datasize);
        if (rc != ERROR_SUCCESS)
        {
            cout << data << endl;
            cout << "there was a problem getting the value" << endl;
        }
    }
    cout << data << endl;

}

1 个答案:

答案 0 :(得分:6)

可能正在返回Unicode数据而您只打印第一个字符。对此的快速测试是将呼叫更改为RegGetValueA