[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

Chapter 4.

 

Creating Win32/x86 Applications



A Win32/x86 application is a stand-alone, executable program that launches when the user double-clicks it in Windows® (or calls it from the command line). Word processors, spreadsheets, paint programs, and utilities are examples of applications.

This chapter includes the following topics:

What is an Application?

Creating an Application

Choosing Libraries for Applications

For additional information, see "Creating Static Libraries for Win32/x86" and "Creating Win32/x86 Dynamic Link Libraries." These sections provide information on creating library projects. For more information on projects in general, refer to the IDE User Guide.


What is an Application?

An application, or "EXE" as it is sometimes called (since the file name usually ends in .EXE), is an executable piece of binary code. It is built using the CodeWarrior® IDE and runs on the platform you choose. You can build an EXE for AMD® processors, generic x86 processors, or Pentium-class processors.


NOTE

To find a list of all the processors you can target, see "x86 Processor."


An EXE can work in conjunction other types of code, such as dynamic-link libraries (DLLs) loaded at runtime, and static libraries linked when you build your EXE. In other words, your EXE can link with or load other types of code to make your application more modular. You can learn more about DLLs and static libraries in "About Static Libraries." and "About Dynamic Link Libraries,"


Creating an Application

To create a Win32/x86 application, perform the following steps:

1. Create a new project.

Choose File > New. The New dialog appears, as shown in Figure 4.1.

New dialog:

2. Select the project category.

Select the preferred project category from the list in the Project tab.

3. Name the project.

Type a name for your project in the Project name field. By convention, a project name ends with .mcp. You may use the Location field or Set button to choose a different location to store the project. Then click OK.

4. Choose stationery.

There are several stationaries to choose from. Which one you use will depend on the task at hand. Select the preferred stationary from the Project Stationary area of the New Project dialog, as shown in Figure 4.2. Then, click OK.

New Project dialog:

5. Add source files to the project.

The project window appears, as shown in Figure 4.3. Most stationery projects contain source files that are just placeholders. If they contain any code at all, the code will not have been written with your particular task in mind. Thus, these placeholder files need to be deleted and replaced with your own code.

Project window:

If you do not already have source files prepared, then you will need to write them. Click New Text File in the CodeWarrior IDE tool bar. An edit window appears, as shown in Figure 4.4. Write your source code, then choose File > Save. The Save document as dialog appears, as shown in Figure 4.5. Type a name for your source file in the File name field, then click Save.

Edit window:
Save document as dialog:

Once you have written your source files or if you already have source files written, select the Source folder in the project window, then choose Project > Add Files. The Select files to add dialog appears, as shown in Figure 4.6. Navigate to your source files, select them (use Control-click to select multiple files), then click Add. The Add Files dialog appears, as shown in Figure 4.7. Add the files to the preferred targets by enabling the options in the Targets area, then click OK.

Select files to add dialog:
Add Files dialog:

6. Remove the source file placeholders from your project.

Select the placeholder files in the Sources folder of the project window and choose Edit > Delete.

7. Examine Target settings.

Choose Edit > Target Settings, where Target is the name of the project's currently selected target. The Target Settings window appears, as shown in Figure 4.8. Use this window to specify various optional settings for your project. The exact settings you can specify depend on:

the language in which your source code is written

the platform for which you are compiling

the size of your project

For Win32/x86 projects, you must specify settings for the target platform, the project type, the compiler, and the linker. There are various other, optional settings that you can specify as well. To learn more about specifying settings beyond what we do here, refer to "Target Settings for Win32/x86."

Target Settings window:

8. Specify target settings.

The Target Settings panel appears by default in the Target Settings window. The settings in this panel are preset by the project stationery, but you can change them if necessary. See "Target Settings" for more information on the Target Settings panel.

9. Set the project type.

Select x86 Target in the Target Settings Panels area. The x86 Target panel appears, as shown in Figure 4.9. Again, the settings are preset for you by the project stationery, but you can modify them if you wish. See "x86 Target" for more information on the x86 Target panel.

x86 Target project settings panel[x eighty-six Target project settings panel]; project settings panels:

x86 Target[project settings panels:x eighty-six Target]>x86 Target panel:

10. Specify language settings.

Select C/C++ Language in the Target Settings Panels area. The C/C++ Language panel appears, as shown in Figure 4.10. Ordinarily, the default settings are fine as they are in this panel, but you are free to change them. For more information about setting language preferences, refer to the C Compilers Reference.

C/C++ Language project settings panel[C CPlusPlus Language project settings panel]; project settings panels:

C/C++ Language[project settings panels:C CPlusPlus Language]>C/C++ Language panel:

11. Specify additional settings.

You can continue to examine other target settings panels and change any settings you wish. For more information on the various panels and settings available, see "Settings Panels for Win32/x86" as well as the relevant sections of the IDE User Guide, and the C Compilers Reference. When you are finished examining project settings, click OK to save your settings and close the Target Settings window.

12. Create New Targets

If you want, you can click on the Targets tab of the project window and choose Project > Create New Target. This allows you to add a special target group to better organize your build. You can also delete targets in this view. If you want to have certain files included in some targets but not in others, select the file and choose View > Project Inspector. The Project Inspector window appears, as shown in Figure 4.11. This window allows you to view information about a selected files and to assign files to specific targets. Click the Targets tab, then enable or disable the options in the Targets area to include or exclude the file from the targets in the project. Refer to the IDE User Guide for more information on managing multiple targets.

Project Inspector window:

13. Build your project.

After your project is created and its contents and all necessary settings are specified, you are ready to compile and debug your code. Choose Project > Make to compile and link your project. If all goes well, the IDE stores the resulting output file in your project folder under the name you specified in the x86 Target settings panel. For more information on compiling and linking, refer to the IDE User Guide. In addition, if you have checked the SYM Format option on the x86 Processor panel and Generate SYM File on the x86 Linker panel, the CodeWarrior IDE will generate a symbol file, which you will need for debugging your code.

14. Run your application.

Once you have successfully built your application, you can run it in the usual way, such as by double-clicking the .exe file icon or selecting it with the mouse and choosing the Open command. If all goes well, congratulations! You have used the CodeWarrior IDE to build a running Win32/x86 application. If not, see "Debugging for Win32/x86" and the IDE User Guide for information on debugging.


Choosing Libraries for Applications

This section briefly describes which CodeWarrior libraries you should include in your Win32 application projects. For a more in-depth discussion, see "Libraries and Runtime Code for Win32/x86."

Generally, you will create an application project with project stationery, so you will not need to add libraries on your own. But, if you change certain project options, this section explains which libraries you may need to change.

The topics in this section include:

  • C/C++ Libraries
  • Win32 SDK Libraries
  • MFC Libraries

  • C/C++ Libraries

    Table 4.1 lists some of the CodeWarrior libraries you might need to add to a C or C++ project. Note that if your application is a C++ application, you must also include the C runtime libraries.

    Libraries for a Win32 application project (Partial List):

     

    Library
    Use
    mwcrtl.lib  
    Metrowerks C/C++ Runtime  
    mwcrtldll.lib  
    The import library for the DLL runtime, MSL C, and MSL C++ dynamic linked libraries  
    ansicx86.lib  
    MSL C library  
    ansicppx86.lib  
    MSL C++ library  
    ansic_winsioux.lib  
    MSL WinSIOUX library  

    In addition to the standard libraries, there are variations for specialized compilers. These include 3DNow!, Microsoft Exceptions settings. Versions of libraries with a final "D" before the filename extension have debug information embedded in them. For example, mwcrtld.lib is the debug version of the Metrowerks C/C++ runtime library.


    NOTE

    Libraries with a 60 number in them are intermediate steps in creating the final library.



    Win32 SDK Libraries

    Any libraries that you may need to include to resolve (at link time) Win32 API calls you made in your code are discussed on the World Wide Web at:


    http://msdn.microsoft.com


    This site includes information on all the libraries you may need, including the commonly used ones listed in Table 4.2. For a more in-depth discussion, see "Libraries for Win32 Development."

    Common Win32 SDK Libraries (Partial List):

     

    Library Name
    Functionality
    Comdlg32.lib  
    Implements common dialog-related code  
    Gdi32.lib  
    Implements GDI calls for graphical rendering  
    Kernel32.lib  
    Implements OS-level calls  
    User32.lib  
    Implements other graphics-related Win32 API calls  


    MFC Libraries

    Any libraries that you need to include to resolve (at link time) Microsoft Foundation Classes (MFC) API calls you made in your code are discussed on the World Wide Web at:


    http://msdn.microsoft.com


    This site includes information on all the libraries you may need, including the commonly used ones listed in Table 4.3. Documentation and resources, including more sample code, for using MFC is also found there.

    Common MFC Libraries :

     

    Library Name
    Functionality
    mfc421.lib  
    MFC Static Library  
    mfc421d.lib  
    MFC Static Library (Debug)  

    Note that you can also build your application to include the MFC DLL instead of statically linking-in the MFC libraries. This is an option that is made available to you when you use project stationery, as described in "Creating an Application." This allows the size of your application to be smaller because the MFC DLL file that is required would need to be installed or already present on the computer on which you are running it.

     


    [ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

    Visit the Metrowerks website at: http://www.metrowerks.com
    For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
    Copyright © 2000, Metrowerks Corp. All rights reserved.

    Last updated: July 21, 2000