2021年4月5日星期一

Reading 64bit registry from 32bit c++ program?

I'm trying to read the registry from my c++ program, this works fine when I run it in 64-bit mode, but when I switch over to 32bit mode it does not. Now I've learned that there are 2 separate parts of the registry, the 64 and 32-bit parts. I read that I should use KEY_WOW64_64KEY but I can't figure out how. The following code is what i had:

    char value[255];      DWORD BufferSize = BUFFER;      RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptography", "MachineGuid", RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);      std::wcout << value << std::endl;      system("pause");  

And it works fine, but when I switch over to 32bit, it doesn't. So I tried the following: replacing RRF_RT_ANY with the RRF_RT_ANY | KEY_WOW64_32KEY

    char value[255];      DWORD BufferSize = BUFFER;      RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptography", "MachineGuid", RRF_RT_ANY | KEY_WOW64_32KEY, NULL, (PVOID)&value, &BufferSize);      std::wcout << value << std::endl;      system("pause");  

But this also doesn't work, what is the correct way to apply this?

It returns a value of "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ"

https://stackoverflow.com/questions/66951334/reading-64bit-registry-from-32bit-c-program April 05, 2021 at 06:08PM

没有评论:

发表评论