How to determine if Windows type DWORD_PTR is supported using ifdef?

There are several new integer types in the Windows API for supporting Win64. They were not always supported; for example, they are not in MSVC6 .

How to write a #if condition to determine if these types are supported with <windows.h> ?

(My code needs to be compiled under different versions of Microsoft Visual C ++, including MSVC6. Therefore, I need to provide my own definitions of these types with #if to disable them in new compilers).

(For search engines, a complete list of types: DWORD_PTR, INT_PTR, LONG_PTR, UINT_PTR, ULONG_PTR)

+3
c ++ c windows visual-c ++ win64
Apr 27 '10 at 17:01
source share
2 answers

The MSC_VER macro is a value that is in the range [1200, 1300) for MSVC 6. Thus, you can use #if MSC_VER>=1200 && MSC_VER<1300 .

EDIT: As Anders said, it’s not really the case that the validity of the test beyond β€œis my MSVC 6 compiler.” However, you can also use:

 #if defined(MAXULONG_PTR) 

Since DWORD_PTR is a value type, it has the maximum value defined for it in basetsd.h .

+5
Apr 27 '10 at 17:08
source share
β€” -

Since these types are typedefs, there is no reliable and reliable way to determine if they are defined at the pre-processor stage. MSN's suggestion to test the compiler version is pretty good, but as Anders pointed out in a comment, a more recent SDK can be used (I think VC6 was supported in the 2003 SDK - I'm not sure if these types are in this SDK or not).

You can check what the SDK defines as a macro that uses these types, for example GetWindowLongPtr :

 #if !defined( GetWindowLongPtr) typedef DWORD DWORD_PTR; #endif 

Kludgy, but I think you could be stuck with kludgy.

+4
Apr 27 2018-10-10T00:
source share



All Articles