Module-Definition Files

Every Windows application, QuickWin application, and Windows library must have a “module-definition file.” A module-definition (.DEF) file is a text file containing one or more statements that define the application's contents and system requirements. When you link a Windows program, the linker uses the information in the .DEF file to determine how to create the application. (DOS programs do not use module-definition files.)

When you choose one of the three Windows program types in the Project dialog box (see Figure 9.2), the Graphical Development Environment tells the linker to expect a module-definition file. The file can have any legal filename but must have the extension .DEF.

The statements required in a .DEF file depend on the type of Windows program you are creating. For details about creating module-definition files for Windows programs, see the following chapters in C for Windows: Chapter 14, “A Generic Windows Application”; Chapter 28, “Dynamic-Link Libraries”; and Appendix C, “QuickWin Programs.”

Default Module-Definition Files

If you build a Windows program (application, DLL, or QuickWin) and your project list does not contain a .DEF file, the Development Environment creates

a default .DEF file with the same name as the project. The program type you choose determines the list of statements that appear in the default file and the action the Development Environment takes regarding the file. The following sections describe the .DEF file and the Development Environment behavior for each program type.

Windows Applications

When you choose Windows EXE in the Program Type box, the default .DEF file created by the Development Environment contains the following statements:

NAME projectname WINDOWAPI

EXETYPE WINDOWS 3.0

STUB 'winstub.exe'

STACKSIZE 5120

HEAPSIZE 1024

The Development Environment pauses after creating the .DEF file and asks whether to use the default file or to cancel the build. If the statements in the default .DEF file are correct for your program, choose to continue the build. If you want to edit the default file or create a new .DEF file, cancel the build. You can then write your .DEF file and start a new build. You will need to write your own .DEF file if you want to add statements to the default file, such as IMPORTS statements for importing routines your program needs.

QuickWin Applications

The default .DEF file created by the Development Environment for a QuickWin application contains the same statements as described above for Windows EXE. However, the Development Environment does not pause to ask you whether to use the .DEF file it creates but instead proceeds with the build using the default .DEF file.

Windows DLLs

The default .DEF file created by the Development Environment for a Windows DLL contains the following statements:

LIBRARY projectname WINDOWAPI

EXETYPE WINDOWS 3.0

CODE PRELOAD MOVABLE DISCARDABLE

DATA PRELOAD SINGLE

HEAPSIZE 1024

As it does for a Windows application described above, the Development Environment pauses after creating the .DEF file for a DLL and asks whether to use the default file or to cancel the build. You can choose to continue the build, or you can cancel the build and write your own .DEF file.