Why _WIN32_WINNT == 0x400 in Qt Creator on Windows 7 machine?
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:
ExitWindow开发者_如何学JAVAsEx(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 targeting at runtime. 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".
When you use the Windows SDK, you can specify which versions of Windows your code can run on. The preprocessor macros WINVER and _WIN32_WINNT specify the minimum operating system version your code supports. When you upgrade an older project, you may need to update your WINVER or _WIN32_WINNT macros. If they're assigned values for an unsupported version of Windows, you may see compilation errors related to these macros. from:https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=vs-2019
精彩评论