RegGetValue returns 1 character.
Jan 1, 2021 at 6:25am UTC
Hi Guys!!!
I have a bit of an issue where the RegGetValue is returning 1 character of the registry keys contents. Any ideas on what I am doing wrong?
1 2 3 4 5 6 7 8 9 10
#define BUFFER 8192
int main()
{
char value[255];
DWORD BufferSize = BUFFER;
RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" , "SystemRoot" , RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
std::cout << value << std::endl;
system("pause" );
}
Thanks for any and all assistance!!
Googie.
Jan 1, 2021 at 6:29am UTC
Strings in the Windows registry are encoded in UTF-16, thus you should be passing a pointer to a wchar_t array. Also, the value of BufferSize should match the actual size of the buffer in bytes.
1 2 3 4
wchar_t value[255];
DWORD BufferSize = sizeof (value);
//...
std::wcout << value << std::endl;
Jan 1, 2021 at 6:34am UTC
Jan 1, 2021 at 7:29am UTC
Thanks for your fast reply guys! It works now!!
I have one last question with the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void Reg() {
wchar_t value[255];
DWORD BufferSize = sizeof (value);
RegGetValue(HKEY_LOCAL_MACHINE, L"registry path here" , L"TEST" , RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
std::wcout << value << std::endl;
char * ascii = new char [wcslen(value) + 1];
wcstombs(ascii, value, wcslen(value));
printf(ascii);
system("pause" );
}
Now when I get the results from "printf(ascii);" the results are correct but it is followed up with jumbled data after the desired result. The console looks like this:
DOUBLE
DOUBLE═²²²²▌▌▌▌▌≥Ao▌Press any key to continue . . .
Any ideas on what I'm doing to get this result?
Many Thanks,
Googie.
Jan 1, 2021 at 10:57am UTC
Topic archived. No new replies allowed.