|
Tools BCC CHMOD CL COFF2OMF COFFIMPLIB DMC DIFF DIFFDIR DUMP DUMPOBJ DUMPEXE EXE2BIN FLPYIMG GREP HC IMPLIB LIB LIBUNRES MAKE MAKEDEP ME OBJ2ASM PATCHOBJ RC RCC SC SHELL SMAKE TOUCH UNMANGLE WHEREIS Compiling Compiling Code C Implementation C++ Implementation Language Extensions Mixing Languages Assembly Language Inline Assembler Optimizing Code Numerics Programming Regular Expressions Acrtused Pragmas Precompiled Headers Predefined Macros Warning Messages Error Messages Runtime Messages Linking Optlink Switches Module Definition Files Operation and Design Error Messages Win32 Programming Win32 Programming DOS and Win16 Programming Memory Models 16 Bit Pointer Types and Type Modifiers Handle Pointers DOS DOS 32 (DOSX) Win16 Win16 DLLs Win16 Prolog/Epilog Virtual Memory For 640Kb DOS C/C++ Extensions Contract Programming __debug statement __debug declaration Dynamic Profiling Embedding C in HTML Porting to DMC++ Switching to DMC++ from Microsoft from Borland Porting Guide |
Win32 Programming GuidelinesThis chapter describes how to use the compiler to create Win32 and Win32s applications. For information about:
What's in This Chapter
Some Basic InformationThe following will help you understand the information in this chapter.
About Win32sWin32s is an NT emulator or operating system extension that allows you to run Win32 applications on a Windows 3.1 host. The "s" in Win32s stands for Win32 subset: Win32s supports almost all Win32 API features.Note: Win32s applications built with C++ Version 7 will only run on version 1.15 and above of Win32s. Advantages of Win32s over Win16Win32s, included with Digital Mars C++, gives you the following advantages over conventional Win16 applications:
Key Win32s featuresMany features are available through the Win32s Applications Programming Interface (API), such as:
Building Win32 and Win32s ApplicationsDigital Mars C++ includes a set of tools that make it easy to create and debug Win32 and Win32s applications from either the command line or within the integrated environment. By setting switches, all the tools— compiler, linker, resource compiler, and resource editors— generate the correct type of 32-bit application. The following is basic information useful for building Win32 and Win32s applications:
Note: To developers using NT: OPTLINK (the linker) does not accept COFF resource files, but does accept standard Microsoft resources files. Compiling Win32 ExecutablesThis section explains how to create various kinds of Win32 executables.Compiling with MFC 3.xIf your Win32 application uses MFC 3.x libraries, see the "READ ME" file included with the distribution for a list of the options, libraries, and #defines you need to build various targets with the latest MFC release. Note that, for all MFC 3.x libraries, you need to compile with the NT (-mn) memory model.Compiling Win32 DLLsTo compile Win32 DLLs, use these compiler options:-mn -WDTo write a Win32 DLL, you need to specify the entry point DllMain(). When the compiler detects a call to DllMain() in a 32-bit compilation, it generates a reference to the _acrtused_ dll startup function, and links with the appropriate startup code. Unlike previous versions of C++, this startup code calls static constructors and performs other initialization steps before calling DllMain(). Converting older Win32 DLLsTo convert Win32 DLLs built with previous versions of C++ to work with this version, make the changes listed below:
Building Console ApplicationsA console application is a character mode application that runs under Windows 95 or NT. Digital Mars C++ supports console mode applications.To compile console applications, use the -mn compiler option, and specify the SUBSYSTEM CONSOLE directive in the .def file. Startup code for console applicationsWhen the compiler detects a call to main() in a 32-bit compilation, it generates a reference to the _acrtused_ con startup function, and links with the appropriate startup code. You no longer need to explicitly link in cc.obj, as with previous versions of C++; it is now part of snn.lib.Compiling Win32s ExecutablesTo compile Win32s executables, use the -mn and -WA compiler options. Note: HP Dashboard does not support Win32s. If you try to debug a Win32s application under Dashboard, the debugger receives a GPF message from the application being debugged.Compiling Win32s DLLsTo compile Win32s executables, use the -mn and -WA compiler options.Note: To create libraries from Windows NT System DLLs (kernel32.dll, for example), use the IMPLIB utility and specify the /system switch. IMPLIB is available only from the command line, not via the IDDE. Win32 Definition File DirectivesThis section lists the directives used in definition files for Win32 programs. For descriptions of these directives see Definition File Directives.NAME name [BASE=number]
LIBRARY name [ BASE= number | PROCESSINIT |
PROCESSTERM | THREADINIT |
THREADTERM ]
DESCRIPTION 'descriptive line'
EXETYPE NT
HEAPSIZE [number, commit]
STACKSIZE [number, commit]
STUB 'filespec'
SUBSYSTEM [ NATIVE | WINDOWS | CONSOLE | POSIX ]
VERSION number[. number]
CODE [READ] [WRITE] [EXECUTE ] [SHARED]
DATA [READ] [WRITE] [EXECUTE] [SHARED]
SEGMENTS
{ name [CLASS 'class']
[READ] [WRITE]
[EXECUTE] [SHARED]
}
IMPORTS { [internal=] externalfile. func }
EXPORTS { parms [=intname] [@number [NONAME]]
[CONSTANT]}
Recompiling Win16 Applications for Win32To convert to a Win32 or Win32s application to a Win16 application created with the C/C++ compilers, try these suggestions:
Converting Non-Digital Mars Win16 Applications to Win32 ApplicationsThe following information will help you convert 16-bit programs developed with other programming tools to be Win32 or Win32s applications.Start with a bug-free Win16 application. Be sure your Win16 application compiles and runs without any compiler or linker errors or warnings. Convert the application to be a Win16 application. For instructions on porting code from Borland or Microsoft, see Switching to Digital Mars C++. Be sure the converted program compiles and runs with Digital Mars C++ without any errors or warnings. Save the original source code and makefile, preferably in another project directory. Now that the application is a Digital Mars Win16 application, convert it to Win32, following the hints above. Finally, after a clean build, preferably with no warnings, test the application.
If you are targeting both Win32 and Win32s, you should test these
applications thoroughly in both environments, as there are a number
of significant differences between Win32 and Win32s.
|