The Need for a Foundation Class Library

Chapter 21 - Procedure-oriented Windows Applications

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Using a Make or Project Utility
There are two ways of putting your Windows applications together: from the command line or from within the integrated environment of the compiler. If you are building applications from the command line, you will need to write a make file. If you are building applications from within the integrated environment, you will need to use the project utility. We very strongly recommend the latter.
The nmake Utility
Microsoft provides a command-line program maintenance utility named NMAKE.EXE. The nmake utility is important when compiling command-line applications that use multiple source code or data segments. The use of the nmake utility requires the development of another text file, called the make file. Make files often do not have a file extension. Thus, for our first example, a command-line make file would be named SWP. The syntax for building an application from the command-line is as simple as typing the following:
nmake swp
The nmake utility is responsible for calling the Visual C++ compiler, linker, and resource compiler with the proper options. Make files also do partial builds of the application. For example, if the source code has changed but the resource code remains unchanged, the make file will just recompile the source code on subsequent operations.
A simple make file, such as one that could be used for the SWP.C application, will look something like this:
all : swp.exe

swp.obj: swp.c
 cl -c -AS -Gsw -Oas swp.c

swp.exe: swp.obj swp.def
 link /NOD swp,,,libw slibcew, swp.def
In a make file, the file named to the left of the colon is the file the nmake utility will update if any of the component files to the right of the colon have been updated. The action taken by the utility is restricted to the appropriate indented lines. Note that a command-line make file is a text file created in any text editor.
However, once again, we recommend the use of the project utility discussed in the next section as the preferred alternative to the command-line nmake utility.
PROJECT UTILITY
Seasoned users will choose to remain within the integrated environment of the Visual C++ compiler and compile and link their applications with the help of the Project utility. The Project utility will create an additional file on your disk with a .DSP file extension. So, in this example, the project file would be named SWP.DSP. Project files are not text files, so we can’t show you the contents of the file, only tell you how to create one. If a project is built within a unique workspace, another file with a .DSW file extension will be created on your disk. The process of using a project file to manage your files is so simple that you will probably never choose to build applications from the command-line again!
To start a new project, use the compiler’s File | New menu to open the New dialog box. Use the Projects folder and select a Win32 Application, as shown in Figure 21-1.
Figure 21-1: A Win32 application is selected for the new TestApp project
The project name for this example is TestApp, as you can see in Figure 21-1. Click the OK button to arrive at an initially blank screen.
To write code for the project, use the compiler’s Project | Add To Project | New… menu selection, as shown in Figure 21-2.
Figure 21-2: A source code file is to be added to the TestApp project
When this selection is made, a New dialog box appears. Using the Text File option, as shown in Figure 21-3, enter the name of the file. In this example, it is TESTAPP.C.
Figure 21-3: A blank text file named TESTAPP.C will be the source code file for this example
It is also possible to select the C++ Source File as the file type; just be sure to name the file TESTAPP.C.
It is now possible to type your source code into this file, as shown in Figure 21-4.
Figure 21-4: Source code can now be typed into the TESTAPP.C file
When the source code is complete, use the File menu to save the project.
If your application requires other files, such as resource files and so on, they can be added to the project at this point. Use the Project | Add To Project | Files… menu selection, to specify the filename.
For all remaining applications in this book, we’ll be developing our own project files and building our applications from within the integrated environment.
The next step in creating a new application is using the Project utility to build an executable file. Before building an application, it is important that all switches are set properly to build a Windows application. The command-line make utility, nmake, allows you to specify this in text form within the file, but the Project utility requires that these switches be set from within the integrated environment. These switches can be set from the Project | Settings… menu. When the Project Settings dialog box is visible, you will be provided with a number of folders. From the General folder, make sure the Microsoft Foundation Class Option is set to “Not Using MFC,” as you can see in Figure 21-5.
Figure 21-5: General compiler settings for a procedure-oriented Windows application
Files are created and saved in a Debug subdirectory by default. When you have completed the project and are ready to generate a release candidate, change to the Release option.
Switch to the C/C++ folder. If you have not changed the defaults, your folder should appear similar to Figure 21-6.
Figure 21-6: C/C++ compiler settings for a Windows application
The default options are satisfactory for almost all applications. As a check, make sure your project options match those shown in the Project Options list in Figure 21-6.
Switch to the Link folder. It should appear similar to Figure 21-7.
Figure 21-7: Link settings for a Windows application
Compare your project options with those shown in Figure 21-3. It is very important that the subsystem be set to /subsystem:windows and not to /subsystem:console. If it is not set in this manner, your application will compile but not link correctly.

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net