Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

c++ get registry key returns only one char

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;

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...