Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if the Windows DWORD_PTR type is supported, using an ifdef?

There are some new integer types in the Windows API to support Win64. They haven't always been supported; e.g. they aren't present in MSVC6.

How can I write an #if condition to detect if these types are supported by <windows.h>?

(My code needs to compile under many different versions of Microsoft Visual C++, including MSVC6. So I need to provide my own definitions of these types, with an #if to disable them in newer compilers).

(For searchers, the full list of types is: DWORD_PTR, INT_PTR, LONG_PTR, UINT_PTR, ULONG_PTR)

like image 283
user9876 Avatar asked Dec 04 '25 21:12

user9876


1 Answers

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

EDIT: As Anders said, this is not really that valid of a test beyond "is my compiler MSVC 6". However, you can also use:

#if defined(MAXULONG_PTR)

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

like image 108
MSN Avatar answered Dec 07 '25 15:12

MSN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!