C++ 什么是 _WIN32_WINNT,它是如何工作的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15111799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:02:40  来源:igfitidea点击:

What is _WIN32_WINNT and how does it work?

c++winapiwindows-7

提问by StudentX

EDIT 2:Ok so I changed to Orwell DevC++ which contains the "winnt.h" that contains #define KEY_WOW64_64KEY 0x0100but it still is not working. (Refer to EDIT 1:)

编辑 2:好的,所以我改为 Orwell DevC++,其中包含包含#define KEY_WOW64_64KEY 0x0100的“winnt.h”,但它仍然无法正常工作。(请参阅编辑 1:)

EDIT 1:I looked into the "winnt.h" which came along the CodeBlock and DevC++ and the DevC++'s is missing the following lines:

编辑 1:我查看了随 CodeBlock 和 DevC++ 一起出现的“winnt.h”,而 DevC++ 缺少以下几行:

#if (_WIN32_WINNT >= 0x0502)
#define KEY_WOW64_64KEY 0x0100
#define KEY_WOW64_32KEY 0x0200
#endif

And putting the above code in the wint.h of DevC++ doesn't work.

而把上面的代码放到DevC++的wint.h里面是不行的。



Original Post:I have a 32bit application (developing in DevC++ and Windows 7 64bit) which reads a 64bit app's registry as one of its task, so I am trying to use "KEY_WOW64_64KEY" flag in RegOpenKeyEx, and found few posts regarding how to use it with _WIN32_WINNT : thisand this

原帖:我有一个 32 位应用程序(在 DevC++ 和 Windows 7 64 位上开发)它读取 64 位应用程序的注册表作为其任务之一,所以我尝试在 RegOpenKeyEx 中使用“KEY_WOW64_64KEY”标志,并且发现很少有关于如何使用的帖子它与 _WIN32_WINNT :这个这个

It worked like charm when I used it in a CodeBlock Project(a test project) but the same code is not working with DevC++, I can't port it to codeblock now since codeblock presents other problems.

当我在 CodeBlock 项目(一个测试项目)中使用它时,它就像魅力一样,但相同的代码不适用于 DevC++,我现在无法将它移植到 codeblock,因为 codeblock 存在其他问题。

How do I make it work with DevC++ ?

我如何使它与 DevC++ 一起工作?

Thanks

谢谢

回答by john.pavan

It defines the version of the windows header files to use. It must be declared before you #include <Windows.h>.

它定义了要使用的 Windows 头文件的版本。它必须在你面前声明#include <Windows.h>

There are a few other similar variables you should probably set if you're going to modify it:

如果您要修改它,您可能应该设置其他一些类似的变量:

MSDN Using Windows Headers

MSDN 使用 Windows 标头

回答by Aniket Inge

  1. _WIN32_WINNTis a preprocessor token, which is replaced by (0x0601)wherever _WIN32_WINNTis used. The preprocessor just scans the whole file and replaces _WIN32_WINNTwith (0x0601)everywhere it is found.
  1. _WIN32_WINNT是一个预处理器令牌,它被替换为(0x0601)where _WIN32_WINNTis used。预处理器只扫描整个文件,并替换_WIN32_WINNT(0x0601)到处发现。

Chances are, there could be ifdefpreprocessor guards that will enable/disable a preprocessor constant. Like:

很有可能,可能会有ifdef预处理器保护来启用/禁用预处理器常量。喜欢:

#ifdef _WIN32_WINNT
#define KEY32 32
#endif

There, KEY32will only be defined IF_WIN32_WINNTis defined.

那里,KEY32只会被定义IF_WIN32_WINNT被定义。

  1. It already works with DevC++.
  1. 它已经适用于 DevC++。