Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ get registry key returns only one char

Tags:

c++

registry

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;

}
like image 255
Tom Avatar asked Jan 01 '26 01:01

Tom


1 Answers

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.

like image 135
Mark Wilkins Avatar answered Jan 02 '26 15:01

Mark Wilkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!