为什么_WIN32_WINNT == 0x400在Qt Creator在Windows 7机器上? [英] Why _WIN32_WINNT == 0x400 in Qt Creator on Windows 7 machine?
问题描述
我使用Qt Creator 2.0.1基于Qt 4.7.0(32位)。操作系统是Windows 7 Ultimate(32位)。
我想使用以下函数调用重新启动Windows:
ExitWindowsEx(EWX_REBOOT,SHTDN_REASON_MAJOR_SYSTEM |
SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY);
我在源代码中添加了windows.h和reason.h,并在LIBS中添加了libuser32
编译代码后,Qt Creator发出错误,说明 SHTDN_REASON_MAJOR_SYSTEM
和 SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY
未在范围中定义。
我查看了mingw附带的reason.h文件。我发现 #define
在 #if
中:
#if(_WIN32_WINNT> = 0x0501)
我查看了 _WIN32_WINNT
的值,它似乎是1024(0x400)。
的版本号,那些 #define
s应该在特定版本之后编译。但是为什么 _WIN32_WINNT
在Windows 7这么低?如何使用 #define
s?我不想将直接值代替 SHTDN_REASON_MAJOR_SYSTEM
和 SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY
。
如果在包含API标题文件之前将其设置为较高的值,则更多的API函数和定义将可用,但使用这些函数可能会导致您的应用程序拒绝以在以前版本的Windows上运行。
可以安全地使用 #define
只要您检查Win32函数中的错误,指示该值不受支持,则从较高的API版本中获取值。但是,使用Win32函数将导致您的应用程序在启动时失败,如DLL import not found错误。
I'm using Qt Creator 2.0.1 based on Qt 4.7.0 (32 bit). The OS is Windows 7 Ultimate (32 bit).
I'd like to restart Windows using the following function call:
ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_SYSTEM |
SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY);
I've added windows.h and reason.h in the source code and added libuser32 in the LIBS section of *.pro file.
After compiling the code, Qt Creator issues an error saying SHTDN_REASON_MAJOR_SYSTEM
and SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY
are not define in the scope.
I looked into reason.h file that comes with mingw. I found the #define
s are inside an #if
:
#if (_WIN32_WINNT >= 0x0501)
I looked into the value of _WIN32_WINNT
which appears to be 1024 (0x400).
I understand this represents some kind of version number and those #define
s should be compiled after a specific version. But why _WIN32_WINNT
is so low on Windows 7? How can I use those #define
s? I do not want to put direct values instead of SHTDN_REASON_MAJOR_SYSTEM
and SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY
.
The value of _WIN32_WINNT
indicates the version of the Win32 API you're compiling against. It has nothing to do with the version of the OS you happen to be using while doing the build.
If you set this to a higher value before including the API header files more API functions and definitions will become available, but making use of those functions may cause your application to refuse to run on previous versions of Windows. Typically, you want to use the lowest value that you can get away with.
It's safe to use #define
values from higher API versions as long as you check for errors from Win32 functions indicating that the value is not supported. Using Win32 functions, however, will cause your application to fail on startup with errors like "DLL import not found".
这篇关于为什么_WIN32_WINNT == 0x400在Qt Creator在Windows 7机器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!