Platform SDK: Win64 Programming Preview |
[This is preliminary documentation and subject to change.]
This topic describes the tools available for you to use in making your application 64-bit ready.
The Win32 and Win64 API elements are virtually identical. The Windows header files have been modified so that you can use them for both Win32 and Win64 code. The Win64-specific types and macros are defined in a new header file, Basetsd.h, which is in the set of header files included by Windows.h. Basetsd.h includes the new data-type definitions you'll use to make your application word-size independent.
The Platform SDK header files contain new data types. These types are primarily for type compatibility with Win32 data types. The new types provide exactly the same typing as the existing types, while at the same time providing support for the upcoming 64-bit Windows. For more information, see The New Data Types or the Basetsd.h header file.
The compiler defines the following macros to identify the platform.
Macro | Meaning |
---|---|
_WIN64 | A 64-bit platform. |
_WIN32 | A 32-bit platform. This value is also defined by the 64-bit compiler for backward compatibility. |
_WIN16 | A 16-bit platform |
The following macros are specific to the architecture.
Macro | Meaning |
---|---|
_M_ALPHA | An Alpha platform, either 32-bit or 64-bit. |
_M_ALPHA64 | A 64-bit Alpha platform. |
_M_IA64 | A 64-bit Intel platform. |
_M_ALPHA32 | A 32-bit Alpha platform. |
_M_IX86 | A 32-bit Intel platform. |
Do not use these macros except with architecture-specific code, instead, use _WIN64, _WIN32, and _WIN16 whenever possible.
Starting with Windows 2000 beta 2, the Platform SDK will include a 64-bit compiler that you can use to identify pointer truncation, improper type casts, and other 64-bit-specific problems. Better tools will be available, but this tool will get you started.
The 64-bit compiler setup and usage instructions are included in the Platform SDK (see Readme64.txt). After you install the compiler, you can run it on a project or set of code. The first time you run the compiler, it will generate many pointer truncation or type mismatch warnings, such as the following:
warning C4311: 'type cast' : pointer truncation from 'unsigned char *' to 'unsigned long '
Use these warnings as a guide to make your code more robust. It is good practice to eliminate all warnings, especially pointer-truncation warnings. For example, the following code can generate the C4311 warning:
buffer = (PUCHAR)srbControl; (ULONG)buffer += srbControl->HeaderLength;
To correct the code, make the following changes:
buffer = (PUCHAR)srbControl; (ULONG_PTR)buffer += srbControl->HeaderLength;
Note that this compiler enables the LLP64 data model.
There is a warning option to assist porting to LLP64. The -Wp64 -W3 switch enables the following warnings:
To build your application, use the linker and libraries provided by the Platform SDK. However, not all of the libraries have an available Win64 version, so your code may not link. The linker and libraries on the Platform SDK are only available for the Compaq Alpha processor.
The Platform SDK is now shipping with a product called Cole. Cole (named after Cole Porter) helps you port your programs so they compile in both a Win32 and Win64 environment. It will flag lines of source code that might be incompatible with Win64 and suggest a method of fixing them. This tool was created using the AST (Abstract Syntax Tree's) Toolkit.