To port a Windows 3.x application, you must revise the declaration of the window procedure. The following is a declaration of a window procedure for a Windows 3.x application.
LONG FAR PASCAL MainWndProc( HWND hWnd,
unsigned message,
WORD wParam,
LONG lParam)
To revise the declaration for Win32, replace the data types used in Windows 3.x as shown in the table. The following code can be compiled as a 32-bit application, but it can still be used to compile 16-bit applications as before:
LRESULT CALLBACK MainWndProc( HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
This table summarizes the changes to the declaration noted in the previous example.
Changes to the Window Procedure Declaration
Windows 3.x | Win32 (portable code) | Reason for changing |
FAR PASCAL | CALLBACK | CALLBACK is guaranteed to use whatever calling convention is appropriate for windows and dialog procedures. |
unsigned | UINT | Meaning is the same, but UINT guarantees portability for future platforms. |
WORD | WPARAM | WORD is always 16 bits. The WPARAM type grows to 32 bits. |
LONG | LPARAM | Meaning is the same (32 bits), but LPARAM guarantees portability for future platforms. |
A significant difference between the Windows 3.x declaration and the portable version involves the wParam parameter, which grows to 32 bits under Win32. Therefore, replacing the WORD type with WPARAM is critical. The WPARAM type varies with the operating system, as does UINT: these types are 16 bits wide under Windows 3.x and 32 bits wide under Win32.
The other changes shown in the table are recommended for code clarity and portability. For example, WPARAM and LPARAM are automatically defined to be the correct types for message parameters, and CALLBACK will always be the correct declaration for window procedures.
A 32-bit wParam message parameter combined with the addresses and handles that grow to 32 bits, means that some messages must be repacked, as described in Handling 32-Bit Messages.