3.1.3 Combined Windows 3.0 and 3.1 Applications

You can create Windows applications that run with Windows 3.0 but also take advantage of newer features when running with Windows 3.1. Such applications consist primarily of Windows 3.0 function calls but conditionally link to and use Windows 3.1 functions.

To build a combined application, mark your application as a Windows 3.0 only executable by using the /30 option with Resource Compiler, but do not set the WINVER define variable to 0x300. You must use the GetVersion function to determine the version of Windows that is running before using any Windows 3.1 functions.

The following example demonstrates how to set a flag if the current system is Windows 3.1:

extern BOOL fWin31;

UINT version;

fWin31 = FALSE;

version = LOWORD(GetVersion());
if (((LOBYTE(version) << 8) | HIBYTE(version)) >= 0x030a) {
    fWin31 = TRUE;
}

For information about interpreting the return value of the GetVersion function, see the Microsoft Windows Programmer's Reference, Volume 2.

Your application can call Windows 3.1 functions directly as long as you link it with the 3.1 version of LIBW.LIB. (It is not necessary to call the GetProcAddress function.) However, you must ensure that Windows 3.1 functions are not called when your application is running with Windows 3.0. The following example demonstrates how this can be done, using the fWin31 flag that was set in the preceding example:

extern BOOL fWin31;

if (fWin31) {
    ScrollWindowEx(hwnd, ...);        /* new for Windows 3.1  */
}
else {
    ScrollWindow(hwnd, ...);        /* Windows 3.0 function */
}

If you create Windows Help files for your application, either use Help Compiler version 3.0 (HC30.EXE) to compile your files, or create a help file for Windows 3.1 and release your help file with the redistributable Windows 3.1 versions of the WINHELP.EXE and WINHELP.HLP files.

If you run a combined application using the debugging version of Windows 3.0, a call to an undefined function causes a warning. The application, however, continues to load and run successfully, as long as the function is not actually called.