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

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

问题描述

我试图从注册表项获取值,最终的程序必须在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 << "\n";
   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 说如果它是'32位代码在64位操作系统上,它不会工作,但我不明白这是什么意思。

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_64KEY KEY_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天全站免登陆