вторник, 19 июля 2011 г.

How can I know if the DWORD_PTR type is defined using ifdef?

Memsize-types DWORD_PTR, INT_PTR, LONG_PTR, UINT_PTR and ULONG_PTR are intended to support 64-bit code and can safely store a pointer regardless of the platform capacity. But these types might be absent in old versions of Windows Platform SDK. The best solution of this problem is to update SDK to the latest version. However, if it is impossible for some reason, you can define these types by yourself.
Since these types are defined by the typedef specifier, there is no single reliable method to check their presence in the SDK version being used with the help of the #ifdef directive at the preprocessing step. However, the maximum value for these types is defined through MAXULONG_PTR in the basetsd.h file and you may do the following:
#if !defined(MAXULONG_PTR)
typedef DWORD DWORD_PTR;
#endif

References

  1. Discussion at Stackoverflow.com. "How to detect if the Windows DWORD_PTR type is supported, using an ifdef?"
  2. MSDN Library. error C2065: 'DWORD_PTR' : undeclared identifier.

Комментариев нет:

Отправить комментарий