Using the Gestalt Manager
Using the Gestalt Manager
The Gestalt Manager includes three functions-Gestalt, NewGestalt, and
ReplaceGestalt. You can use the Gestalt function to obtain information
about software or hardware components available on the current machine. You
can use NewGestalt to register new software modules (such as drivers and
patches) with the Operating System. Use ReplaceGestalt to replace the
function associated with a particular selector code by some other function.
Note: Most applications do not need to use either NewGestalt or
Determining Features of the Operating Environment
When your application needs information about a specific software or
hardware feature that can be provided by the Gestalt function, your
application can pass Gestalt a selector code (or selector) as one of the
parameters. The selector code is simply an indication of what information your
application currently needs. There are two types of selector codes- predefined
selector codes that are always recognized by Gestalt, and application- defined
selector codes that applications may register with Gestalt by calling the
NewGestalt function.
If Gestalt can determine the requested information, it returns that
information in its second parameter, known as the response parameter. If
Gestalt cannot obtain the desired information, it returns a result code
indicating the cause of the error; in that case, the value of the response
parameter is un defined. You should always check the result code returned by
Gestalt to make sure that the response parameter contains meaningful
information.
Note: When passed one of the predefined selector codes, Gestalt
does not move or purge memory and therefore may be called at any
time, even at interrupt time. However, selector functions associated
with application- defined selector codes may move or purge memory,
and applications can alter Gestalt's predefined selector functions. As
a result, it is safest to assume that Gestalt might always move or
purge memory. The NewGestalt function may move memory and
should not be called at interrupt time.
There are two types of predefined selector codes: codes that return
information that your application can use to guide its actions (known as
environmental selectors), and codes that provide information only and should
never be used as an indication of some feature's existence (known as
informational selectors).
It is particularly important that you understand the difference between
environmental and informational selectors. The response returned by Gestalt
when it is passed an informational selector is for your (or the user's)
edification only and should never be used by your application as a means of
determining whether some specific software or hardware feature is available.
For example, you can use Gestalt to test for the version of the ROM installed
on a particular machine, but you should never use this information to guide
any of your application's actions. Routines you expect to be in ROM may
actually be in RAM; hence, you cannot determine that some routine usually
found in ROM is not present simply by looking at the ROM version. Also,
routines contained in ROM may have been patched by the system at startup
time, in which case the system might not have the features that you think it
has on the basis of the reported ROM version. Similar remarks apply to other
informational selectors such as ROM size, machine type, and System file
version.
You can use the following environmental selectors to determine information
about the operating environment.
gestaltAddressingModeAttr addressing mode attributes
gestaltAliasMgrAttr Alias Mgr attributes
gestaltAppleEventsAttr Apple events attributes
gestaltAppleTalkVersion AppleTalk version
gestaltAUXVersion A/UX version if present
gestaltConnMgrAttr Connection Mgr attributes
gestaltCRMAttr Comm Resource Mgr attrs
gestaltCTBVersion Comm Toolbox version
gestaltBAccessMgrAttr Data Access Mgr attrs
gestaltDITLExtAttr Dialog Mgr extensions
gestaltEasyAccessAttr Easy Access attributes
gestaltEditionMgrAttr Edition Manager attributes
gestaltExtToolboxTable Ext Toolbox trap table base
gestaltFindFolderAttr FindFolder attributes
gestaltFontMgrAttr Font Mgr attributes
gestaltFPUType FPU type
gestaltFSAttr file-system attributes
gestaltFXfrMgrAttr File Transfer Mgr attrs
gestaltHardwareAttr hardware attributes
gestaltHelpMgrAttr Help Mgr attributes
gestaltKeyboardType keyboard type
gestaltLogicalPageSize logical page size
gestaltLogicalRAMSize logical RAM size
gestaltLowMemorySize low-memory area size
gestaltMiscAttr miscellaneous attributes
gestaltMMUType MMU type
gestaltNotificationMgrAttr Notification Mgr attrs
gestaltNuBusConnectors NuBus connector bitmap
gestaltOSAttr O/S attributes
gestaltOSTable O/S trap table base
gestaltParityAttr parity attributes
gestaltPhysicalRAMSize physical RAM size
gestaltPopupAttr pop-up CEF attributes
gestaltPowerMgrAttr Power Mgr attributes
gestaltPPCToolboxAttr PPC Toolbox attributes
gestaltProcessorType processor type
gestaltQuickdrawVersion QuickDraw version
gestaltResourceMgrAttr Resource Mgr attributes
gestaltScriptCount # of active script systems
gestaltScriptMgrVersion Script Mgr version
gestaltSerialAttr serial hardware attributes
gestaltSoundAttr sound attributes
gestaltStandardFileAttr Standard File attributes
gestaltStdNBPAttr StandardNBP attributes
gestaltTermMgrAttr Terminal Mgr attributes
gestaltTextEditVersion TextEdit version
gestaltTimeMgrVersion Time Mgr version
gestaltToolboxTable Toolbox trap table base
gestaltVersion Gestalt version
gestaltVMAttr virtual memory attributes
The following informational selectors are provided for informational
purposes only. You can display the information returned when using these
selectors, but you should never use this information as an indication of what
software features or hardware may be available.
gestaltMachineIcon machine ICON/cicn res ID
gestaltMachineType machine type
gestaltROMSize ROM size
gestaltROMVersion ROM version
gestaltSystemVersion System file version
Interpreting Gestalt Responses explains the exact meaning of each of
these selectors and of the values returned by Gestalt in each case.
Determining Whether Gestalt Is Available
Because the Gestalt Manager currently exists only in system software
versions 6.0.4 and later (and in ROM on the Macintosh IIci, the Macintosh
Por table, and later machines), you should make certain that it is actually
available before attempting to call it. You can do this by using the
TrapAvailable function defined previously in Determining Whether a
Trap Is Available under About Compatibility. The Listing below uses
that function to determine whether the Gestalt Manager is available.
Determining whether Gestalt is available
// Determining whether Gestalt is available.
// See About Compatibility for the definition of TrapAvailable.
#include <Traps.h>
#define _Gestalt 0xA1AD
Boolean GestaltAvailable(void)
{
}
Note: If you are using THINK C 5.0 or later, THINK Pascal 4.0 or
later, or the MPW development system version 3.2 or later, then
you do not need to perform this check because these versions provides
glue routines that allow you to call Gestalt, NewGestalt, and
ReplaceGestalt even if they are not in ROM or in the System file.
However, if you are programming in assembly language, this glue is
not provided (and you still need to check that the trap is available
before calling it). See the individual descriptions of Gestalt,
NewGestalt, and ReplaceGestalt for more information about the
behavior of the glue routines under systems which do not support the
Gestalt Manager.
If you need to know at several different places in your application whether
Gestalt is available, it may be more efficient to define a global Boolean
variable that you can test before calling Gestalt. The listing below illustrates
how to do this. Once again, this code uses the TrapAvailable function defined
earlier.
Using Gestalt to determine the Time Manager version
// Using Gestalt to determine the Time Manager version
// See About Compatibility for the definition of TrapAvailable
#include <Traps.h>
#include <GestaltEqu.h>
#define _Gestalt 0xA1AD
Boolean gHasGestalt; // true if Gestalt is implemented
main()
{
OSErr myErr;
long myFeature; // will receive Gestalt return value
gHasGestalt = TrapAvailable(_Gestalt);
if (gHasGestalt) { // Not necessary under development systems
// which contain Gestalt glue
myErr = Gestalt( gestaltTimeMgrVersion, &myFeature);
if (myErr != noErr)
DoError(myErr);
}
}
This sample code returns (in the myFeature parameter) the version of the
Time Manager available on the current machine. Before using that
information, however, you should test the result code to make sure that
Gestalt was able to determine the requested information.
Interpreting Gestalt Responses
When your application calls Gestalt to get information about the operating
environment, the meaning of the value that Gestalt returns in the response
parameter depends on the selector code with which it was called. For example,
if you call Gestalt using the gestaltTimeMgrVersion selector, it returns a
version code in the low-order byte of the response parameter. In this case, a
returned value of 3 indicates that the extended Time Manager is available.
In almost all cases, the last few characters in the selector's symbolic name
form a suffix that indicates what type of value you can expect Gestalt to
return in the response parameter. For example, if the final characters in a
Gestalt selector are Size, then Gestalt returns a size in the response
parameter. The following list shows the meaningful suffixes.
Suffix Meaning
Attr The returned value is a range of 32 bits, the meaning of which
must be determined by comparison with a list of constants. Note
that bit 0 is the least significant bit of the long word.
Count The returned value is a number indicating how many of the
indicated type of item exist.
Size The returned value is a size. Sizes reported by Gestalt are
usually in bytes.
Table The returned value is the base address of a table.
Type The returned value is an index describing a particular type of
feature.
Version The returned value is a version number. Implied decimal
points may separate digits of the returned value. For example,
a value of 0x0605 returned in response to the
gestaltSystemVersion selector indicates that system software
system 6.0.5 is present.
Selectors that have the suffix Attr deserve special attention; they cause
Gestalt to return a bit field that your application must interpret in order to
determine whether a desired feature is present. For example, the gestaltOSAttr
selector requests information about a number of Operating System features. To
determine whether a particular Operating System feature is available, you
need to read the appropriate bit in the response parameter, as the Listing
below illustrates.
Interpreting a bit field response
// Interpreting a bit field response
#include <GestaltEqu.h>
short myBit, myErr;
long myFeature; // will receive Gestalt return value
Boolean gHasGestalt;
if (gHasGestalt) {
myErr = Gestalt( gestaltOSAttr, &myFeature);
if (myErr != noErr)
DoError(myErr);
else {
myBit = gestaltTempMemSupport;
if (BitTst(&myFeature, 31-myBit))
printf("temporary memory support available\n");
else
printf("temporary memory support not available\n");
}
}