什么是 32 &64 位 C++ 代码? [英] What is 32 & 64 bit c++ code?

查看:30
本文介绍了什么是 32 &64 位 C++ 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从注册表项中获取一个值,最终程序必须同时在 32 和 32 上运行.64位机器.

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

目前的代码是:

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

我从 RegGetValue 得到错误2",并查看了这个 RegOpenKeyEx/RegGetValue 在存在的键上返回 ERROR_FILE_NOT_FOUND 这表示如果它是64 位操作系统上的 32 位代码",它将不起作用,但我不明白这是什么意思.

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.

是需要针对不同架构编译的程序,还是32位特有的RegGetValue?

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

抱歉,我的大部分 C++ 编程都是在 64 位计算机成为主流之前完成的,而且我在此后偶尔编写的项目都没有遇到这个问题.

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.

推荐答案

在 64 位 Windows 上有两个注册表视图,32 位视图和 64 位视图.这在 MSDN 上标题为 访问备用注册表视图的主题中进行了描述.

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.

默认情况下,32 位进程将从 32 位视图中读取,而 64 位进程将从 64 位视图中读取.如果您希望从特定视图读取,无论流程的架构如何,您都需要提供以下标志之一:KEY_WOW64_64KEYKEY_WOW64_32KEY.

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.

所以,如果你需要的数据是 32 位视图,则通过KEY_WOW64_32KEY.如果数据在 64 位视图中传递 KEY_WOW64_64KEY.如果数据可以在任一键中,请检查两次,一次通过 KEY_WOW64_32KEY,再次通过 KEY_WOW64_64KEY.

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.

这篇关于什么是 32 &amp;64 位 C++ 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆