简体   繁体   中英

What is 32 & 64 bit c++ code?

I'm trying to get a value from a registry key, and the final program has to work on both 32 & 64 bit machines.

The code so far is:

   HKEY hKey; 
   LONG Result1;
   LONG result2;
   Result1 = RegOpenKeyEx(HKEY_CLASSES_ROOT,L"Word.Application\\CurVer",0,KEY_READ,&hKey);
    cout << Result1;
    cout << "\n";
   TCHAR value[255];
   DWORD BufferSize = 255;
   result2 = RegGetValue(hKey, L"Word.Application\\CurVer", L"", RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
   cout << result2;

I'm getting the error '2' back from RegGetValue, and looked at this RegOpenKeyEx/RegGetValue return ERROR_FILE_NOT_FOUND on keys that exist which says that it will not work if it's '32 bit code on a 64 bit OS' but I do not understand what this means.

Is it the program that has to be compiled for different architectures, or is it RegGetValue that is specific to 32 bit?

Sorry, most of my C++ programming was done back before 64bit computers became mainstream, and none of the occasional items I've written since have had this problem.

On 64 bit Windows there are two registry views, the 32 bit view and the 64 bit view. This is described over on MSDN in the topic titled Accessing an Alternate Registry View .

By default a 32 bit process will read from the 32 bit view, and a 64 bit process will read from the 64 bit view. If you wish to read from a particular view, irrespective of the architecture of the process you need to supply one of the following flags: KEY_WOW64_64KEY or KEY_WOW64_32KEY .

So, if the data that you need is in the 32 bit view, pass KEY_WOW64_32KEY . If the data is in the 64 bit view pass KEY_WOW64_64KEY . If the data could be in either key, check twice, once passing KEY_WOW64_32KEY and once again passing KEY_WOW64_64KEY .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM