Skip to content

Latest commit

 

History

History
134 lines (105 loc) · 6.61 KB

Readme.md

File metadata and controls

134 lines (105 loc) · 6.61 KB

Win16 Example Application

Table of Contents

Introduction

This application is an example 16 bit Windows application written in C. It accompanies the Building Win16 GUI Applications in C article on Transmission Zero.

The application runs under Windows 3.0 to Windows ME, and all versions of Windows NT which support Win16 apps (Windows NT 3.1 to at least the x86 version of Windows 10). It does not run under Windows 1 or 2, but there is a Windows 1 Version which is compatible with Windows 1 and 2 (but not compatible with Windows 9x).

The application can be built using Visual C++ 1.5x. You can download Visual C++ 1.52 if you have a Visual Studio Subscription. If you don't have a subscription, you can download the Windows Server 2003 DDK which contains the 16 bit command line tools (most of which are from Visual C++ 1.52). The 16 bit binaries can be found in "bin\bin16" of the installed DDK, include files in "inc\inc16", and lib files in "lib\lib16". A number of the binaries come in two versions, one with and one without a "16" suffix, e.g. "cl.exe" and "cl16.exe". Despite the different filenames, the file contents are identical.

The application can also be built with Open Watcom, which is free to download.

With a few small changes to the Makefile, the application will build with Microsoft C / C++ 7.0 and the Windows 3.1 SDK. It won't build with the Windows 3.0 SDK because the headers don't define some of the required types, and it does not have the "ver.h" header which is required for the version information resource.

Building the Application

To build the application with the Microsoft Visual C++ 1.5x GUI, go to "project", "open", then open "Win16App.mak". To choose a debug or release build, go to "options" then "project". The project can be built using the "build" or "rebuild" toolbar items, or via the "project" menu.

To build the application from the command line with Visual C++ 1.5x, launch a command prompt, run the "MSVCVARS.BAT" file which can be found in the Visual C++ "bin" directory, and then navigate to the directory containing the Makefile. Run "nmake /f Win16App.mak" to build. This also works with the Windows Server 2003 DDK, but instead of running "MSVCVARS.BAT", you will need to add the "bin16" directory to your "%PATH%" environment variable, "inc16" to "%INCLUDE%", and "lib16" to "%LIB%".

To build the application in Open Watcom, open the project up in the IDE, and choose the "Make" option from the "Targets" menu. You can switch between debug and release builds by going to "Targets", "Target Options", and choosing "Use Development Switches" or "Use Release Switches".

Smart Callbacks

This application makes use of so-called "smart callbacks". This means the data segment register is loaded from the stack segment register on entry to any callback function which is called by Windows. The result of this is that it is not necessary to list the callback functions in the application's module definition file, and it is not necessary to use "MakeProcInstance" to create a thunk when (e.g.) displaying a dialog box. In Visual C++ this is achieved by marking callback functions with the "__export" modifier, and using the "/GA /GEs /GEm" compiler options (optimise far function epilogs, load DS from SS, and increment BP on entry to the callback--required only for real mode stack walking support). You can also use the "/GEf" option, which means all far functions are given the code to load DS from SS regardless of whether they are callback functions. This is slightly less efficient, but does mean that callback functions don't require the "__export" modifier.

Open Watcom does the same thing, but uses the "-zWs" compiler option to include the segment loading code.

Refer to the Windows 1 Version for an example application which uses "MakeProcInstance" rather than smart callbacks.

Terms of Use

Refer to "License.txt" for terms of use.

Known Problems

The Open Watcom build of the application doesn't work correctly under Windows 3.0 when running in Real Mode. The application will start but the menu is missing and the about dialog won't display. I've found Open Watcom to be a bit hit and miss, where certain seemingly harmless changes of compiler option result in an application which crashes, so it may be possible to fix this by changing the compiler options. It runs fine under Windows 3.0 in Standard Mode and 386 Enhanced Mode.

The Open Watcom build of the application has optimisations switched off. With optimisations enabled, the application crashes on startup.

If you have any other problems or questions, please ensure you have read this readme file and the Building Win16 GUI Applications in C article. If you are still having trouble, you can get in contact.

Changelog

  1. 2017-05-21: Version 1.4
  • Removed unnecessary whitespace from source files.
  • Corrected min / max window size handling, which should have been using a far pointer for the MINMAXINFO struct.
  • Removed the original Makefile as it just duplicates the functionality of the Visual C++ Makefile.
  • Various updates to compiler and linker options to ensure consistency between Visual C++ and Open Watcom builds.
  1. 2014-11-09: Version 1.3
  • Added a Makefile project for use with the Visual C++ GUI.
  • Refactored some of the code to split the source code files by functionality.
  1. 2013-09-07: Version 1.2
  • Removed superfluous LOWORD() macros which had been applied to WPARAMs.
  1. 2013-08-26: Version 1.1
  • Added a VERSIONINFO resource to the executable, so that version information can be viewed in File Manager or Windows Explorer.
  • Open Watcom build now runs in Windows 3.0 (but not in real mode).
  • Ensured all source files are no more than 8.3 characters long.
  1. 2011-07-06: Version 1.0
  • First release.

Transmission Zero 2017-05-21