So, the declaration of GetSystemTimes
in winbase.h
(on my machine, Windows 7 VS2005)
#if _WIN32_WINNT >= 0x0501
BOOL
WINAPI
GetSystemTimes(
__out_opt LPFILETIME lpIdleTime,
__out_opt LPFILETIME lpKernelTime,
__out_opt LPFILETIME lpUserTime
);
#endif
Sure, I can just #define _WIN32_WINNT 0x0501
, but that just doesn't seem right and I can't find an explanation of why this is the case and what my alternatives are. Anyone have some insight here?
It's #if
ed out because it wasn't added to the API until Windows NT v5.01, AKA Windows XP. Your program is expected to #define
the symbol _WIN32_WINNT
to the hex value of your minimum targeted Windows version: see Using the Windows Headers .
If you don't define _WIN32_WINNT
, it assumes you're targeting the lowest common denominator, and it doesn't provide newer API features. So if you want to use them, you need to define _WIN32_WINNT
to an appropriate value and understand that your code won't run on older versions of Windows, which is usually fine -- nobody's going to complain that your code doesn't run on Windows 98.
According to MSDN documentation, the possibility you mentioned is the intended usage. Although I agree with you that it can seem odd, this way of doing things lets you build projects targeting platforms with different minimum operating system versions, so you aren't surprised when a Windows API function isn't available on the target machine.
GetSystemTimes()
Declared in Winbase.h
#if _WIN32_WINNT >= 0x0501 // look at this
BOOL
WINAPI
GetSystemTimes(
LPFILETIME lpIdleTime,
LPFILETIME lpKernelTime,
LPFILETIME lpUserTime
);
#endif // (_WIN32_WINNT >= 0x0501)
use the include like this :
#define _WIN32_WINNT 0x0501
#include <Windows.h>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.