c++ get registry key returns only one char

南笙酒味 提交于 2019-12-29 01:43:26

问题


I'm trying to retrieve a value of a key but i'm only getting the first char of the value.. can anyone help?

my code:

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:


It is probably returning Unicode data and you are only printing the first character. A quick test of that would be to change the call to RegGetValueA.



来源:https://stackoverflow.com/questions/4483087/c-get-registry-key-returns-only-one-char

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!