Windows Prolog/Epilog Code Generation
From the IDDE, use the Windows Prolog/ Epilog subpage on the Build page of the IDDE's Project Settings dialog box.
32 Bit Windows Prolog/Epilog Code Generation
Switch | Description |
---|---|
-WA | Win32 EXE |
-WD | Win32 DLL |
no -W switch | Win32 console EXE app |
16 Bit Windows Prolog/Epilog Code Generation
Switch | Description |
---|---|
-W | Same as -W1 if no modifier switches |
-W- | Not a windows compile (default) |
-W1 | Real mode Windows app/DLL |
-W2 | Real mode Windows app/DLL with exported and callback functions marked with __export |
-W3 | Real mode Windows app with smart callbacks |
-WA | Protected mode Windows EXE, with callback functions all marked as __export. |
-WD | Protected mode Windows DLL, with callback and exported functions all marked as __export. |
Modifier | Description |
---|---|
a | Reload DS from DS for far functions |
b | Assume DS != DGROUP |
d | Reload DS from DGROUP for far functions |
e | Generate EXPDEF records in .OBJ file for __export functions |
f | Mark all far functions as __export |
m | Generate INC BP / DEC BP to mark far stack frames |
r | Generate reload of DS only if __export or __loadds functions |
s | Reload DS from SS for far functions (smart callbacks) |
t | Use fixups instead of CS. This is needed for real mode, where selector values can change as code moves around. |
u | Reload DS from DGROUP for near and far functions (same as -mu) (same as marking all functions as __loadds) |
v | Save/restore caller's DS in far functions |
w | Assume SS != DS (same as -mw) |
x | Program will be run under Windows |
- | Turn off subsequent modifiers |
+ | Turn on subsequent modifiers |
Modifers a,d,s,v are mutually exclusive.
Switch | Equivalent |
---|---|
-W1 | -Wtxema -D_WINDOWS |
-W2 | -Wtxemar -D_WINDOWS |
-W3 | -Wtxems -D_WINDOWS |
-WA | -Wtxrs -D_WINDOWS |
-WD | -Wtxerdw -D_WINDOWS -D_WINDLL |
-WD-r | -Wtxedw -D_WINDOWS -D_WINDLL |
Recommended:
- For "I don't care, just make it work", simply use -W. This will produce the most inefficient code.
- For maximum program speed and compactness, use the -WA or -WD switches.
- Use the L memory model for DLLs.
- Use the L memory model for most application programming. Many anachronistic Windows programming books insist on the S or M model, but the reasons for that have gone away with the obsolescence of real mode.
- Abandon real mode (Windows 3.1 has abandoned it).
- Normally use -4 (486 code) or -5 (Pentium code), unless you expect your code to be used on an 8088 or a 286. Marking your app as only running in enhanced mode will ensure that it won't be accidentally run on an 8088 or a 286.
- If you are using -WA or -WD and need to run a debugger on the result, use the m modifier. This enables many debuggers to distinguish between a near call frame and a far call frame.
- Declare all exported and callback functions with __export.
Don't Do This:
- DON'T use -W3 or -WA for code to be used in a DLL.
- DON'T use smart callbacks (-Ws) for code to be used in a DLL.
- DON'T use -W2, -WA or -WD and then fail to mark as __export those functions to be used as callbacks or exports.
- DON'T use -WA or -WD for code that might be used in Windows real mode.
Microsoft C6 switch compatibility for Windows compiling:
MSC | DMC | Description |
---|---|---|
-Gw | -W | Full Windows prolog/epilog for far functions |
-GW | -W2 | Reduced prolog/epilog, Note 1 |
-Au | -mwu | assume SS != DS and load DS on each function |
-Aw | -mw | assume SS != DS |
Note 1: DMC will still generate the full prolog/epilog for __far __export functions, MSC6 will not.
Microsoft C7/VC switch compatibility for Windows compiling:
MSC | DMC | Description |
---|---|---|
-Gw | -W | Full Windows prolog/epilog for far functions |
-Au | -mwu | assume SS != DS and load DS on each function |
-Aw | -mw | assume SS != DS |
-GA | -WA | optimized protected mode Windows apps |
-GD | -WD | optimized protected mode Windows DLLs |
-GEa | -Wa | load DS from AX |
-GEd | -Wd | load DS from DGROUP |
-GEe | -We | emit EXPDEF records for all exported functions |
-GEf | -W-r | create prolog/epilog code for all far functions |
-GEm | -Wm | add inc BP / dec BP to prolog / epilog of far functions |
-GEr | -W2v | real mode, reduced prolog for non-exported functions |
-GEs | -Ws | load DS from SS |
-Gq | -Wtxme | compatibility with MSC6 -GW |
-GW | -Wtxmev -D_WINDOWS | reduced prolog for real mode Windows functions |
Special Feature
The -Wb switch (assume DS != DGROUP) causes the compiler to issue a warning whenever a segment fixup is done to DGROUP. If your program is using an alternate data segment, this could mean that a DGROUP fixup is a program bug.
A DGROUP fixup can be triggered (in large data model) by things like:
static int x; static int *px = &x; /* DGROUP fixup generated */ static char *p = "abc"; /* DGROUP fixup generated */
To get rid of the fixup, the pointers can be made near:
static int __near *px = (int __near *)&x; static char __near *p = "abc";
These will generate DGROUP relative fixups, not DGROUP segment fixups. Alternatively, the pointers can be initialized at runtime (the compiler generates code that uses DS to initialize segment values).
Eliminating DGROUP segment fixups is useful for:
- special purpose code where the data segment needs to be moved around.
- embedded systems where the data segment will be initialized from an image in ROM.
- 16 bit Windows DLLs where the DLL was made to be multi-instanced by creating multiple copies of DGROUP at runtime.
The -Wb switch can be highly useful in finding difficult to track down bugs in such code. -Wb does not affect code generation at all, it only reports when a DGROUP segment fixup is generated.
Note that -Wb will issue errors if you are using __loadds (because DS is reloaded from DGROUP) or if you are using -Wd (load DS from DGROUP Windows prologs).
-W tells the compiler to ignore case when linking to make the programs more compatible with existing Windows programs (many of which are linked that way). When developing new programs, do not ignore case, since C and C++ are case-sensitive languages. Ignoring case can cause bugs that are difficult to trace.
To compile a Windows program without ignoring case, use the options -W -L/noi
dmc -W -L/noi winprog.c
References For 16 Bit Windows Prolog/Epilogs
Chapter 21
"Programmer's Reference, Volume 1"
Microsoft Windows SDK 3.1
Chapters 7 and 19
Programming Windows 3.1, Third Edition
Charles Petzold
Microsoft Press
ISBN 1-55615-395-3