为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2?
我正在拨打以下电话:
result = RegOpenKeyEx(key, s, 0, KEY_READ, &key);
(C++,Visual Studio 5,Vista 64位)。
即使“regedit
”显示该密钥存在,它也会失败并显示错误代码 2(“找不到文件”)。 这段代码一直可以在 32 位 XP 上运行。 为什么明明存在文件却显示“找不到文件”?
I was making the following call:
result = RegOpenKeyEx(key, s, 0, KEY_READ, &key);
(C++, Visual Studio 5, Vista 64bit).
It is failing with error code 2 ("File not found") even though "regedit
" shows that the key exists. This code has always worked on 32bit XP. Why is it "file not found" when it clearly is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我发现我可以使用标志来解决我的问题:
KEY_WOW64_64KEY
,如下所示:有关完整说明:注册表中的 32 位和 64 位应用程序数据
I discovered that I could solve my problem using the flag:
KEY_WOW64_64KEY
, as in:For a full explanation: 32-bit and 64-bit Application Data in the Registry
在 Windows 64 位系统上,注册表实际上分为两部分。 一部分由 64 位进程使用,一部分由 32 位进程使用。
例如,如果 32 位应用程序以编程方式写入它认为是 HKLM\SOFTWARE\Company\Application 的内容,则它实际上由 WoW64 层重定向到 HKLM\SOFTWARE\Wow6432Node\Company\Application。
因此,当您运行 32 位应用程序并调用 RegOpenKeyEx 时,它实际上针对的是 Wow6432Node\ 文件夹,而不是常规的 \SOFTWARE 节点。
On a Windows 64-bit system the Registry is actually divided into two parts. One section is used by 64-bit processes, and one part by 32-bit processes.
For example, if a 32-bit application programatically writes to what it believes is HKLM\SOFTWARE\Company\Application, it's actually redirected by the WoW64-layer to HKLM\SOFTWARE\Wow6432Node\Company\Application.
So when you run your 32-bit application and call RegOpenKeyEx it's actually working against the Wow6432Node\ folder, and not the regular \SOFTWARE node.
您必须使用“使用多字节字符集”进行编译或将代码中的字符串转换为(LPWSTR)
You have to compile with "Use Multi-Byte Character Set" or cast string in code to (LPWSTR)
我有类似的问题。
我正在使用:
那不起作用。 我这样尝试并且有效:
I had a similar problem.
I was using:
That didn't work. I tried it like this and it worked:
是的,win7 64B,进一步添加标志 KEY_WOW64_64KEY ,就可以了。
如果不起作用,请参阅 http://msdn。 microsoft.com/en-us/library/ms724897(v=VS.85).aspx
yes,win7 64B,add further flag KEY_WOW64_64KEY ,it will work.
if not work, refer to http://msdn.microsoft.com/en-us/library/ms724897(v=VS.85).aspx