Q: My application does things that just won't work in the
Classic environment. How do I detect the Classic environment
so that I can tell the user why certain functionality has
been disabled?
A: You can detect the Classic environment using Gestalt ,
as shown in Listing 1.
// At the time of writing the latest version of Universal
// Interfaces was 3.3.2. These definitions are not in UI 3.3.2,
// but will be in the next release version.
enum {
gestaltMacOSCompatibilityBoxAttr = FOUR_CHAR_CODE('bbox'),
/* Classic presence and features */
gestaltMacOSCompatibilityBoxPresent = 0,
/* True if running under the Classic */
gestaltMacOSCompatibilityBoxHasSerial = 1,
/* True if Classic serial support is implemented. */
gestaltMacOSCompatibilityBoxless = 2
/* True if we're Boxless (screen shared with
Carbon/Cocoa) */
};
static Boolean RunningOnClassic(void)
{
UInt32 response;
return (Gestalt(gestaltMacOSCompatibilityBoxAttr,
(SInt32 *) &response) == noErr)
&& ((response &
(1 << gestaltMacOSCompatibilityBoxPresent))
!= 0);
}
|
Listing 1. Detecting whether you're
running in the Classic environment.
|
Q: My Carbon application does things on traditional Mac
OS that just won't work on Mac OS X. How do I detect that
I'm running on Mac OS X so that I can do things the right
way on that platform?
A: DTS recommends that you test for specific
functionality rather than for an entire platform. For
example, if your application needs access to non-Carbon APIs
on traditional Mac OS, we recommend that you access those
APIs using GetSharedLibrary and
FindSymbol ; if the
GetSharedLibrary call fails, you don't have
access to the functionality, regardless of the platform.
On the other hand, we recognize that in some cases there
is no convenient functional test, and only a platform test is
possible. In such cases, your Carbon application can detect
whether it is running on Mac OS X using Gestalt , as shown in
Listing 2.
static Boolean RunningOnCarbonX(void)
{
UInt32 response;
return (Gestalt(gestaltSystemVersion,
(SInt32 *) &response) == noErr)
&& (response >= 0x01000);
}
|
Listing 2. Detecting whether your
Carbon application is running on Mac OS X.
|
|