home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-13 | 4.4 KB | 159 lines | [TEXT/CWIE] |
- // Simple framework for Macintosh sample code
- //
- // David Hayward and Nick Thompson
- // Developer Technical Support
- // AppleLink: DEVSUPPORT
- //
- // Copyrite 1995, Apple Computer,Inc
- //
- // This file contains the AppleEvent utility routines.
- //
- // 9/16/94 nick first cut
- // 11/16/94 david added a global gAE_available to aeGlobals.c
- // changeg AE_available to set/clear the global
-
-
- #include <Gestalt.h>
- #include <AppleEvents.h>
-
- #include "aeUtils.h"
-
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC GLOBALS
- |**| ==============================================================================
- \**/
- AEAddressDesc gSelfPSNAddress; // A self-addressed address descriptor record using GetCurrentProcess()
- AEAddressDesc gSelfAddress; // A self-addressed address descriptor record using kCurrentProcess
- ProcessSerialNumber gSelfPSN; // This application's psn
- AEDesc gNullDesc; // A null descriptor record
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE GLOBALS
- |**| ==============================================================================
- \**/
- OSErr gAE_present_err = 1;
- OSErr gAE_available_err = 1;
- OSErr gAE_initialized_err = 1;
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- AE_present
- *------------------------------------------------------------------------------*
- This function returns noErr if apple event support is present
- (i.e passes gestalt) and returns an error otherwise.
- It also sets the private global gAE_present_err based on the result.
- \*------------------------------------------------------------------------------*/
- OSErr AE_present ( void )
- {
- OSErr err;
- long response;
-
- if ( !gAE_present_err )
- return noErr;
-
- err = Gestalt(gestaltAppleEventsAttr,&response) ;
- if (!err)
- if ((response & (1<<gestaltAppleEventsPresent)) == 0 )
- err = 1 ; // should return something else
-
- gAE_present_err = err;
- return err;
- }
-
-
- /*------------------------------------------------------------------------------*\
- AE_available
- *------------------------------------------------------------------------------*
- This function returns noErr if apple event support is available
- (i.e present and initialized) to the application and returns an error otherwise.
- It also sets the global gAE_available_err based on the result.
- \*------------------------------------------------------------------------------*/
- OSErr AE_available ( void )
- {
- OSErr err;
-
- if ( !gAE_available_err )
- return noErr;
-
- err = AE_present();
- if ( !err )
- err = AE_initialize();
-
- gAE_available_err = err;
- return err ;
- }
-
- /*------------------------------------------------------------------------------*\
- AE_initialize
- *------------------------------------------------------------------------------*
- This function initializes all the apple event stuff.
- It should be called early in the application.
- \*------------------------------------------------------------------------------*/
- OSErr AE_initialize ( void )
- {
- OSErr err;
- ProcessSerialNumber currPSN;
-
- if ( !gAE_initialized_err )
- return noErr;
-
- err = AE_present();
- if ( !err )
- {
- currPSN.highLongOfPSN = 0;
- currPSN.lowLongOfPSN = kCurrentProcess; // Use this instead of GetCurrentProcess *//
-
- err = GetCurrentProcess(&gSelfPSN);
-
- err = AECreateDesc( typeProcessSerialNumber,
- (Ptr)&gSelfPSN,
- sizeof(ProcessSerialNumber),
- &gSelfPSNAddress) ;
-
- err = AECreateDesc( typeProcessSerialNumber,
- (Ptr)&currPSN,
- sizeof(ProcessSerialNumber),
- &gSelfAddress) ;
-
- gNullDesc.descriptorType = typeNull; // Initialize the global null descriptor record.
- gNullDesc.dataHandle = nil;
- }
-
- gAE_initialized_err = err;
- return err;
- }
-
-
- //-----------------------------------------------------------------------
- // utility routine to ensure we got all required parameters from the
- // appleevent passed in.
-
- OSErr MyGotRequiredParams ( AppleEvent *theAppleEvent )
- {
- DescType returnedType;
- Size actualSize;
- OSErr err ;
-
- err = AEGetAttributePtr(theAppleEvent,keyMissedKeywordAttr,typeWildCard,
- &returnedType,nil,0,&actualSize) ;
- if (err == errAEDescNotFound)
- err = noErr ;
- else if (err==noErr)
- err = errAEEventNotHandled;
- return err ;
- }
-
-
-