Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Programmer's Guide to MacApp / Part 1 - MacApp Theory and Architecture
Chapter 4 - Launching and Terminating an Application


Terminating the Application

MacApp includes a general-purpose mechanism for patching Toolbox traps, described in"Trap Patching," beginning on page 82. That mechanism is used to guarantee the application has a chance to perform necessary cleanup, even when it is terminated abnormally.

During initialization, MacApp uses its trap-patching mechanism to patch the ExitToShell Toolbox trap so that the call goes to the ExitToShellCleanupMacApp routine. That routine gets the trap address for ExitToShell, calls CleanupMacApp, then calls ExitToShell, terminating the application.

The CleanupMacApp routine first unpatches the ExitToShell patch. It then calls gApplication->Terminate, giving the application a chance to do any special cleanup before it relinquishes control. Patching ExitToShell ensures that gApplication->Terminate is called, even if a user forces the application to quit. The CleanupMacApp routine finally frees various items and unpatches any other traps the application has patched, a service that is likely to make your application popular with other programs.

The Terminate method is implemented in TEventHandler, but does nothing in that implementation. Your application class can override Terminate if it needs to do any special cleanup.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
25 JUL 1996