The WinMain Procedure

The entry point for any Windows application—3.x, 95, 98, or NT—is the WinMain procedure. Outwardly, this portion of an application has not changed, at least in most cases.

In any of these versions of Windows, the WinMain procedure is called as:

int PASCAL WinMain( HANDLE hInstance,         // 3.x, NT/95/98 
                    HANDLE hPrevInstance,
                    LPSTR  lpszCmdParam,
                    int    nCmdShow  )
{
   ... same for Windows 3.x, Windows NT, Windows 98, et al ...
}

The body of the WinMain procedure also remains the same for these versions.

What is not apparent to programmers, however, is which definitions have changed. For example, under Windows 3.x, the data type HANDLE has a 16-bit value; under Windows 98/95/NT, it has a 32-bit value. Still, as long as the function parameters have not changed, these definition changes are handled by the compiler and, for the programmer, are not immediately relevant.

In other cases, however, the changes are relevant and are reflected in the format and parameter declarations. For example, in the WndProc procedure, which (under this or another name) forms the heart of every Windows program, the 3.x and 98/95/NT version declarations are similar, but not identical.

For Windows 3.x, the WndProc declaration appears as:

long FAR PASCAL WndProc( HWND hwnd,   WORD msg,     // 3.x
                         WORD wParam, LONG lParam )

For Windows 98/95/NT, the WndProc declaration is slightly different, appearing as:

long FAR PASCAL WndProc( HWND hwnd,   UINT msg,     // 98/95/NT 
                         UINT wParam, LONG lParam )

In both cases, the WndProc procedure is called with four arguments: hwnd, msg, wParam, and lParam. The first of these, hwnd, has transparently changed from a 16-bit to a 32-bit argument, because the definition of HWND has changed. The second and third parameters, however, are declared as WORD values in Windows 3.x; for 98/95/NT, they become UINT, or 32-bit unsigned integer values. Only the fourth argument, lParam, remains unchanged as a LONG, or 32-bit signed value. Thus, where the WndProc procedure under Windows 3.x was called with a total of 80 bits (10 bytes) of information, under 98/95/NT, the calling arguments have expanded to a total of 128 bits (16 bytes).

Remember, however, even though the fourth parameter, lParam, remains unchanged and is defined, for consistency, as a long signed integer, this parameter does not determine how this data will be used or in what forms. Furthermore, except for the hwnd parameter, each of these 32-bit values may be interpreted as one or more individual arguments.

© 1998 SYBEX Inc. All rights reserved.