Using Proper Data Types

Windows 3.x source code often uses the type WORD interchangeably with types such as HWND and HANDLE. For example, the type cast (WORD) might be used to cast a data type to a handle:

hWnd = (WORD) SendMessage( hWnd, WM_GETMDIACTIVATE, 0, 0 );

This code compiles Windows 3.x applications correctly because both the WORD type and handles are 16 bits. But the code produces errors when compiled for Win32 because handles (such as HWND types) grow to 32 bits while the WORD type is still 16 bits.

Examine each occurrence of WORD casts and data definitions in your code, and revise as follows:

In the portable version of the previous example, the (WORD) cast is replaced by (HWND):

hWnd = (HWND) SendMessage( hWnd, WM_GETMDIACTIVATE, 0, 0 );

In general, it is best to use the most specific type possible. Avoid using a generic handle type such as HANDLE, and use a more specific type such as HPEN. You should also define specific types for application-specific objects you create.