-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing7.html
executable file
·1452 lines (1227 loc) · 57.4 KB
/
listing7.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>QISA - /MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAppleEvents.cp</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Networking/index.html">Networking</a> > <a href="../../samplecode/Networking/idxDarwin-date.html">Darwin</a> > <A HREF="javascript:location.replace('index.html');">QISA</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">QISA</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAppleEvents.cp</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppearance/MoreAppearance.cp</option>
<option value="listing2.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppearance/MoreAppearance.h</option>
<option value="listing3.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEDataModel.c</option>
<option value="listing4.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEDataModel.h</option>
<option value="listing5.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEObjects.c</option>
<option value="listing6.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEObjects.h</option>
<option value="listing7.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAppleEvents.cp</option>
<option value="listing8.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAppleEvents.h</option>
<option value="listing9.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCarbonEvents/MoreCarbonEvents.c</option>
<option value="listing10.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCarbonEvents/MoreCarbonEvents.h</option>
<option value="listing11.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCFQ/MoreCFQ.c</option>
<option value="listing12.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCFQ/MoreCFQ.h</option>
<option value="listing13.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreControls/MoreControls.cp</option>
<option value="listing14.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreControls/MoreControls.h</option>
<option value="listing15.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreDialogs/MoreDialogs.cp</option>
<option value="listing16.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreDialogs/MoreDialogs.h</option>
<option value="listing17.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreInterfaceLib/MoreInterfaceLib.c</option>
<option value="listing18.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreInterfaceLib/MoreInterfaceLib.h</option>
<option value="listing19.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreInterfaceLib/RemoteAccessInterface.h</option>
<option value="listing20.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreMemory/MoreMemory.c</option>
<option value="listing21.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreMemory/MoreMemory.h</option>
<option value="listing22.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreOSUtils/MoreOSUtils.c</option>
<option value="listing23.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreOSUtils/MoreOSUtils.h</option>
<option value="listing24.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreProcesses/MoreProcesses.cp</option>
<option value="listing25.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreProcesses/MoreProcesses.h</option>
<option value="listing26.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreQuickDraw/MoreQuickDraw.cp</option>
<option value="listing27.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreQuickDraw/MoreQuickDraw.h</option>
<option value="listing28.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCF.c</option>
<option value="listing29.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCF.h</option>
<option value="listing30.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFCCLScanner.c</option>
<option value="listing31.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFCCLScanner.h</option>
<option value="listing32.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFDigest.c</option>
<option value="listing33.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFDigest.h</option>
<option value="listing34.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFHelpers.c</option>
<option value="listing35.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFHelpers.h</option>
<option value="listing36.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFPortScanner.c</option>
<option value="listing37.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFPortScanner.h</option>
<option value="listing38.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSecurity/MoreSecurity.c</option>
<option value="listing39.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSecurity/MoreSecurity.h</option>
<option value="listing40.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSetup.h</option>
<option value="listing41.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreTextUtils/MoreTextUtils.cp</option>
<option value="listing42.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreTextUtils/MoreTextUtils.h</option>
<option value="listing43.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreUNIX/MoreUNIX.c</option>
<option value="listing44.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreUNIX/MoreUNIX.h</option>
<option value="listing45.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreWindows/MoreWindows.cp</option>
<option value="listing46.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreWindows/MoreWindows.h</option>
<option value="listing47.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/MoreNetworkSetup.c</option>
<option value="listing48.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/MoreNetworkSetup.h</option>
<option value="listing49.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/NetworkSetupHelpers.c</option>
<option value="listing50.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/NetworkSetupHelpers.h</option>
<option value="listing51.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/OldStyleAPI/OldOTConfigLib.h</option>
<option value="listing52.html">/QISA.c</option>
<option value="listing53.html">/QISA.h</option>
<option value="listing54.html">/QISAPanels.c</option>
<option value="listing55.html">/QISAPanels.h</option>
<option value="listing56.html">/QISAPlatform.c</option>
<option value="listing57.html">/QISAPlatform.h</option>
<option value="listing58.html">/QISAPlatformCFM/QISAPlatformCFM.c</option>
<option value="listing59.html">/QISAPlatformCFM/QISAPlatformCFMPrefix.h</option>
<option value="listing60.html">/QISAPlatformMach-O/QISAPlatformMach-O.c</option>
<option value="listing61.html">/QISAPlatformMach-O/QISASetupTool.c</option>
<option value="listing62.html">/ReadMeAboutQISA.html</option></select>
</p>
</form>
<p><strong><a href="QISA.zip">Download Sample</a></strong> (“QISA.zip”, 610.6K)<BR>
<strong><a href="QISA.dmg">Download Sample</a></strong> (“QISA.dmg”, 903.9K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/* File: MoreAppleEvents.cp Contains: Apple Event Manager utilities. DRI: George Warner Copyright: Copyright (c) 2000-2001 by Apple Computer, Inc., All Rights Reserved. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Change History (most recent first):$Log: MoreAppleEvents.cp,v $Revision 1.25 2002/11/25 18:40:02 eskimo1Convert OSErr to OSStatus; also got rid of "implicit arithmetic conversion" warnings.Revision 1.24 2002/11/08 22:53:36 eskimo1Convert nil to NULL. Convert MoreAssertQ to assert. Moved a bunch of stuff to MoreAEDataModel. Include our header early so as to detect any missing dependencies in the header.Revision 1.23 2002/10/16 20:32:11 geowaradded MoreAEfprintDesc routine and changed desc parameters to pAEDesc.Revision 1.22 2002/10/03 00:02:40 geowarbug fix - corrected improper usage of PSN fields & constants.Revision 1.21 2002/03/08 23:51:00 geowarMore cleanup.Fixed memory leak in MoreAETellSelfToSetCFStringRefPropertyRevision 1.20 2002/03/07 20:31:51 geowarGeneral clean up.Added recovery code to MoreAESendEventReturnPString.New API: MoreAECreateAEDescFromCFString.Revision 1.19 2002/02/19 18:54:57 geowarWritten by: => DRI:Revision 1.18 2002/01/16 19:11:06 geowarerr => anErr, (anErr ?= noErr) => (noErr ?= anErr)Added MoreAESendEventReturnAEDesc, MoreAESendEventReturnAEDescList,MoreAETellSelfToSetCFStringRefProperty, & MoreAEGetCFStringFromDescriptor routines.Revision 1.17 2001/11/07 15:50:50 eskimo1Tidy up headers, add CVS logs, update copyright. <16> 21/9/01 Quinn Changes for CWPro7 Mach-O build. <15> 8/28/01 gaw CodeBert (error -> pError, theAppleEvent -> pAppleEvent, etc.) <14> 15/2/01 Quinn MoreAECreateAppleEventTargetID is not supported for Carbon builds because all of its required declarations are defined CALL_NOT_IN_CARBON. Also some minor fixes prompted by gcc warnings. <13> 26/5/00 Quinn Eliminate bogus consts detected by MPW's SC compiler. <12> 4/26/00 gaw Fix bug, swapped creator & file type parameters <11> 27/3/00 Quinn Remove MoreAEDeleteItemFromRecord. It's functionality is covered by AEDeleteKeyDesc. <10> 20/3/00 Quinn Added routines to deal with "missing value". Added MoreAECopyDescriptorDataToHandle. Added MoreAEDeleteItemFromRecord. <9> 3/9/00 gaw Y2K! <8> 3/9/00 gaw API changes for MoreAppleEvents <7> 3/9/00 GW Intergrating AppleEvent Helper code. First Check In <6> 6/3/00 Quinn Added a bunch of trivial wrapper routines. George may come along and change all these soon, but I needed them for MoreOSL. <5> 1/3/00 Quinn Change the signature for AEGetDescData to match the version we actually shipped. <4> 2/15/99 PCG add AEGetDescDataSize for non-Carbon clients <3> 1/29/99 PCG add AEGetDescData <2> 11/11/98 PCG fix header <1> 11/10/98 PCG first big re-org at behest of Quinn Old Change History (most recent first): <2> 10/11/98 Quinn Convert "MorePrefix.h" to "MoreSetup.h". <2> 6/16/98 PCG CreateProcessTarget works with nil PSN <1> 6/16/98 PCG initial checkin*/// Conditionals to setup the build environment the way we like it.#include "MoreSetup.h"//********** Our Prototypes ****************************************#include "MoreAppleEvents.h"#if !MORE_FRAMEWORK_INCLUDES //********** Universal Headers **************************************** #include <AERegistry.h> #include <AEHelpers.h> #include <AEObjects.h> #include <AEPackObject.h> #include <ASRegistry.h> //#include <FinderRegistry.h> #include <Gestalt.h>#endif#include <cstdio>//********** Project Headers ****************************************#include "MoreAEDataModel.h"#include "MoreAEObjects.h"#include "MoreProcesses.h"#include "MoreMemory.h"//********** Private Definitions ****************************************enum { kFinderFileType = 'FNDR', kFinderCreatorType = 'MACS', kFinderProcessType = 'FNDR', kFinderProcessSignature = 'MACS'};static AEIdleUPP gAEIdleUPP = NULL;//*******************************************************************************#pragma mark ==> Create Target Descriptors for AEvents */******************************************************************************** Create and return an AEDesc for the process target with the specified PSN. If no PSN is supplied the use the current process pAEEventClass ==> The class of the event to be created. pAEEventID ==> The ID of the event to be created. pAppleEvent ==> Pointer to an AppleEvent where the event record will be returned. <== The Apple event. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone ____________*/pascal OSStatus MoreAECreateProcessTarget(ProcessSerialNumber* pPSN, AEDesc* pAppleEvent){ ProcessSerialNumber self; if (!pPSN) { pPSN = &self; self.lowLongOfPSN = kCurrentProcess; self.highLongOfPSN = 0; } return AECreateDesc (typeProcessSerialNumber,pPSN,sizeof(*pPSN),pAppleEvent);} // MoreAECreateProcessTarget//*******************************************************************************#pragma mark ==> Create AEvents */******************************************************************************** Create and return an AppleEvent of the given class and ID. The event will be targeted at the current process, with an AEAddressDesc of type typeProcessSerialNumber. pAEEventClass ==> The class of the event to be created. pAEEventID ==> The ID of the event to be created. pAppleEvent ==> Pointer to an AppleEvent where the event record will be returned. <== The Apple event. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone ____________*/pascal OSStatus MoreAECreateAppleEventSelfTarget( AEEventClass pAEEventClass, AEEventID pAEEventID, AppleEvent* pAppleEvent){ OSStatus anError = noErr; ProcessSerialNumber selfPSN = {0, kCurrentProcess}; anError = MoreAECreateAppleEventProcessTarget( &selfPSN, pAEEventClass, pAEEventID, pAppleEvent ); return ( anError );}//end MoreAECreateAppleEventSelfTarget/******************************************************************************** Create and return an AppleEvent of the given class and ID. The event will be targeted at the process specified by the target type and creator codes, with an AEAddressDesc of type typeProcessSerialNumber. pType ==> The file type of the process to be found. pCreator ==> The creator type of the process to be found. pAEEventClass ==> The class of the event to be created. pAEEventID ==> The ID of the event to be created. pAppleEvent ==> Pointer to an AppleEvent where the event record will be returned. <== The Apple event. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone procNotFound \xD0600 No eligible process with specified descriptor ____________*/pascal OSStatus MoreAECreateAppleEventSignatureTarget( OSType pType, OSType pCreator, AEEventClass pAEEventClass, AEEventID pAEEventID, AppleEvent* pAppleEvent ){ OSStatus anError = noErr; ProcessSerialNumber psn = {0, kNoProcess}; // <12> bug fix, pCreator & pType parameters swapped. anError = MoreProcFindProcessBySignature( pCreator, pType, &psn ); if ( noErr == anError ) { anError = MoreAECreateAppleEventProcessTarget( &psn, pAEEventClass, pAEEventID, pAppleEvent ); } return anError;}//end MoreAECreateAppleEventSignatureTarget/******************************************************************************** Create and return an AppleEvent of the given class and ID. The event will be targeted at the application with the specific creator. psnPtr ==> Pointer to the PSN to target the event with. pAEEventClass ==> The class of the event to be created. pAEEventID ==> The ID of the event to be created. pAppleEvent ==> Pointer to an AppleEvent where the event record will be returned. <== The Apple event. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone procNotFound \xD0600 No eligible process with specified descriptor ____________*/pascal OSStatus MoreAECreateAppleEventCreatorTarget( const AEEventClass pAEEventClass, const AEEventID pAEEventID, const OSType pCreator, AppleEvent* pAppleEvent){ OSStatus anError; AEDesc targetDesc; assert(pAppleEvent != NULL); MoreAENullDesc(&targetDesc); anError = AECreateDesc(typeApplSignature, &pCreator, sizeof(pCreator), &targetDesc); if (noErr == anError) anError = AECreateAppleEvent(pAEEventClass, pAEEventID, &targetDesc, kAutoGenerateReturnID, kAnyTransactionID, pAppleEvent); MoreAEDisposeDesc(&targetDesc); return anError;}//end MoreAECreateAppleEventCreatorTarget/******************************************************************************** Create and return an AppleEvent of the given class and ID. The event will be targeted with the provided PSN. psnPtr ==> Pointer to the PSN to target the event with. pAEEventClass ==> The class of the event to be created. pAEEventID ==> The ID of the event to be created. pAppleEvent ==> Pointer to an AppleEvent where the event record will be returned. <== The Apple event. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone procNotFound \xD0600 No eligible process with specified descriptor ____________*/pascal OSStatus MoreAECreateAppleEventProcessTarget( const ProcessSerialNumberPtr psnPtr, AEEventClass pAEEventClass, AEEventID pAEEventID, AppleEvent* pAppleEvent ){ OSStatus anError = noErr; AEDesc targetAppDesc = {typeNull,NULL}; anError = AECreateDesc (typeProcessSerialNumber, psnPtr, sizeof( ProcessSerialNumber ), &targetAppDesc); if ( noErr == anError ) { anError = AECreateAppleEvent( pAEEventClass, pAEEventID, &targetAppDesc, kAutoGenerateReturnID, kAnyTransactionID, pAppleEvent); } MoreAEDisposeDesc( &targetAppDesc ); return anError;}//end MoreAECreateAppleEventProcessTarget/******************************************************************************** Create and return an AppleEvent of the given class and ID. The event will be targeted with the provided TargetID. pTargetID ==> Pointer to the TargetID to target the event with. pAEEventClass ==> The class of the event to be created. pAEEventID ==> The ID of the event to be created. pAppleEvent ==> Pointer to an AppleEvent where the event record will be returned. <== The Apple event. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone procNotFound \xD0600 No eligible process with specified descriptor ____________*/#if CALL_NOT_IN_CARBON// See comment in header file.pascal OSStatus MoreAECreateAppleEventTargetID( const TargetID* pTargetID, AEEventClass pAEEventClass, AEEventID pAEEventID, AppleEvent* pAppleEvent ){ OSStatus anError = noErr; AEDesc targetAppDesc = {typeNull,NULL}; anError = AECreateDesc (typeTargetID, pTargetID, sizeof( TargetID ), &targetAppDesc); if ( noErr == anError ) { anError = AECreateAppleEvent( pAEEventClass, pAEEventID, &targetAppDesc, kAutoGenerateReturnID, kAnyTransactionID, pAppleEvent); } MoreAEDisposeDesc( &targetAppDesc ); return anError;}//end MoreAECreateAppleEventTargetID#endif#pragma mark ==> Send AppleEvents *#if 0//* De-appreciated! Don't use! Use one of the more specific routines (w/idle proc) below.pascal OSErr MoreAESendAppleEvent (const AppleEvent* pAppleEvent, AppleEvent* pAEReply){ OSErr anErr = noErr; AESendMode aeSendMode = kAEAlwaysInteract | kAECanSwitchLayer; if (pAEReply) { aeSendMode |= kAEWaitReply; MoreAENullDesc(pAEReply); } anErr = AESend (pAppleEvent, pAEReply, aeSendMode, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); return anErr;}//end MoreAESendAppleEvent#endif 0/******************************************************************************** Send the provided AppleEvent using the provided idle function. Will wait for a reply if an idle function is provided, but no result will be returned. pIdleProcUPP ==> The idle function to use when sending the event. pAppleEvent ==> The event to be sent. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendEventNoReturnValue( const AEIdleUPP pIdleProcUPP, const AppleEvent* pAppleEvent ){ OSStatus anError = noErr; AppleEvent theReply = {typeNull,NULL}; AESendMode sendMode; if (NULL == pIdleProcUPP) sendMode = kAENoReply; else sendMode = kAEWaitReply; anError = AESend( pAppleEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, pIdleProcUPP, NULL ); if ((noErr == anError) && (kAEWaitReply == sendMode)) anError = MoreAEGetHandlerError(&theReply); MoreAEDisposeDesc( &theReply ); return anError;}//end MoreAESendEventNoReturnValue/******************************************************************************** Send the provided AppleEvent using the provided idle function. Return the direct object as a AEDesc of pAEDescType pIdleProcUPP ==> The idle function to use when sending the event. pAppleEvent ==> The event to be sent. pDescType ==> The type of value returned by the event. pAEDescList <== The value returned by the event. RESULT CODES ____________ noErr 0 No error paramErr -50 No idle function provided and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendEventReturnAEDesc( const AEIdleUPP pIdleProcUPP, const AppleEvent *pAppleEvent, const DescType pDescType, AEDesc *pAEDesc){ OSStatus anError = noErr; // No idle function is an error, since we are expected to return a value if (pIdleProcUPP == NULL) anError = paramErr; else { AppleEvent theReply = {typeNull,NULL}; AESendMode sendMode = kAEWaitReply; anError = AESend(pAppleEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, pIdleProcUPP, NULL); // [ Don't dispose of the event, it's not ours ] if (noErr == anError) { anError = MoreAEGetHandlerError(&theReply); if (!anError && theReply.descriptorType != typeNull) { anError = AEGetParamDesc(&theReply, keyDirectObject, pDescType, pAEDesc); } MoreAEDisposeDesc(&theReply); } } return anError;} // MoreAESendEventReturnAEDesc/******************************************************************************** Send the provided AppleEvent using the provided idle function. Return the direct object as a AEDescList pIdleProcUPP ==> The idle function to use when sending the event. pAppleEvent ==> The event to be sent. pAEDescList <== The value returned by the event. RESULT CODES ____________ noErr 0 No error paramErr -50 No idle function provided and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendEventReturnAEDescList( const AEIdleUPP pIdleProcUPP, const AppleEvent* pAppleEvent, AEDescList* pAEDescList){ return MoreAESendEventReturnAEDesc(pIdleProcUPP,pAppleEvent,typeAEList,pAEDescList);} // MoreAESendEventReturnAEDescList/******************************************************************************** Send the provided AppleEvent using the provided idle function. Return data (at pDataPtr) of type pDesiredType pIdleProcUPP ==> The idle function to use when sending the event. pAppleEvent ==> The event to be sent. theValue <== The value returned by the event. RESULT CODES ____________ noErr 0 No error paramErr -50 No idle function provided and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendEventReturnData( const AEIdleUPP pIdleProcUPP, const AppleEvent *pAppleEvent, DescType pDesiredType, DescType* pActualType, void* pDataPtr, Size pMaximumSize, Size *pActualSize){ OSStatus anError = noErr; // No idle function is an error, since we are expected to return a value if (pIdleProcUPP == NULL) anError = paramErr; else { AppleEvent theReply = {typeNull,NULL}; AESendMode sendMode = kAEWaitReply; anError = AESend(pAppleEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, pIdleProcUPP, NULL); // [ Don't dispose of the event, it's not ours ] if (noErr == anError) { anError = MoreAEGetHandlerError(&theReply); if (!anError && theReply.descriptorType != typeNull) { anError = AEGetParamPtr(&theReply, keyDirectObject, pDesiredType, pActualType, pDataPtr, pMaximumSize, pActualSize); } MoreAEDisposeDesc(&theReply); } } return anError;} // MoreAESendEventReturnData/******************************************************************************** Send the provided AppleEvent using the provided idle function. Return a SInt16 (typeSmallInteger). pIdleProcUPP ==> The idle function to use when sending the event. pAppleEvent ==> The event to be sent. theValue <== The value returned by the event. RESULT CODES ____________ noErr 0 No error paramErr -50 No idle function provided and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendEventReturnSInt16( const AEIdleUPP pIdleProcUPP, const AppleEvent* pAppleEvent, SInt16* pValue){ DescType actualType; Size actualSize; return MoreAESendEventReturnData(pIdleProcUPP,pAppleEvent,typeShortInteger, &actualType,pValue,sizeof(SInt16),&actualSize);} // MoreAESendEventReturnSInt16/******************************************************************************** Send the provided AppleEvent using the provided idle function. Returns a PString. pIdleProcUPP ==> The idle function to use when sending the event. pAppleEvent ==> The event to be sent. pStr255 <== The value returned by the event. RESULT CODES ____________ noErr 0 No error paramErr -50 No idle function provided and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendEventReturnPString( const AEIdleUPP pIdleProcUPP, const AppleEvent* pAppleEvent, Str255 pStr255){ DescType actualType; Size actualSize; OSStatus anError; anError = MoreAESendEventReturnData(pIdleProcUPP,pAppleEvent,typePString, &actualType,pStr255,sizeof(Str255),&actualSize); if (errAECoercionFail == anError) { anError = MoreAESendEventReturnData(pIdleProcUPP,pAppleEvent,typeChar, &actualType,(Ptr) &pStr255[1],sizeof(Str255),&actualSize); if (actualSize < 256) pStr255[0] = (UInt8) actualSize; else anError = errAECoercionFail; } return anError;} // MoreAESendEventReturnPString#pragma mark ==> Functions for talking to ourselfs/******************************************************************************** Send an AppleEvent of the specified Class & ID to myself using the default idle function. pEventID ==> The event to be sent. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendToSelfNoReturnValue( const AEEventClass pEventClass, const AEEventID pEventID){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. OSStatus anError = noErr; if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(pEventClass,pEventID,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pSelection, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); // Always dispose of objects as soon as you are done (helps avoid leaks) if (noErr == anError) anError = MoreAESendEventNoReturnValue(gAEIdleUPP, &tAppleEvent); } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } return anError;} // MoreAESendToSelfNoReturnValue/******************************************************************************** Send an AppleEvent of the specified Class & ID to myself using the default idle function. Wait for a reply and extract a SInt16 result. pEventClass ==> The event class to be sent. pEventID ==> The event ID to be sent. pValue <== Where the return SInt16 will be stored. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAESendToSelfReturnSInt16( const AEEventClass pEventClass, const AEEventID pEventID, SInt16* pValue){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. OSStatus anError = noErr; if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(pEventClass,pEventID,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pSelection, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); // Always dispose of objects as soon as you are done (helps avoid leaks) if (noErr == anError) anError = MoreAESendEventReturnSInt16(gAEIdleUPP, &tAppleEvent, pValue); } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } return anError;}//end MoreAESendToSelfReturnSInt16/******************************************************************************** Send a get data (kAEGetData) AppleEvent to myself using the default idle function. Wait for a reply and extract a SInt16 result. pPropType ==> The property type. pValue <== Where the resulting SInt16 will be stored. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAETellSelfToGetSInt16Property(const DescType pPropType,SInt16* pValue){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. OSStatus anError = noErr; if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(kAECoreSuite,kAEGetData,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pPropType, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); // Always dispose of objects as soon as you are done (helps avoid leaks) if (noErr == anError) anError = MoreAESendEventReturnSInt16(gAEIdleUPP, &tAppleEvent, pValue); } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } return anError;}//end MoreAETellSelfToGetSInt16Property/******************************************************************************** Send a get data (kAEGetData) AppleEvent to myself using the default idle function. Wait for a reply and extract a Str255 result. pPropType ==> The property type. pValue <== Where the resulting Str255 will be stored. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAETellSelfToGetStr255Property(const DescType pPropType,Str255 pValue){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. OSStatus anError = noErr; if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(kAECoreSuite,kAEGetData,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pPropType, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); // Always dispose of objects as soon as you are done (helps avoid leaks) if (noErr == anError) anError = MoreAESendEventReturnPString(gAEIdleUPP, &tAppleEvent, pValue); } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } return anError;}//end MoreAETellSelfToGetStr255Property/******************************************************************************** Send a set data (kAESetData) AppleEvent to myself with a SInt16 parameter and using the default idle function. pPropType ==> The property type. pValue ==> The SInt16 value to be set. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAETellSelfToSetSInt16Property(const DescType pPropType,SInt16 pValue){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. OSStatus anError = noErr; if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(kAECoreSuite,kAESetData,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pPropType, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); // Always dispose of objects as soon as you are done (helps avoid leaks) if (noErr == anError) { anError = AEPutParamPtr(&tAppleEvent, keyAEData, typeSInt16, &pValue, sizeof(SInt16)); if (noErr == anError) anError = MoreAESendEventNoReturnValue(gAEIdleUPP, &tAppleEvent); } } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } return anError;}//end MoreAETellSelfToSetSInt16Property/******************************************************************************** Send a set data (kAESetData) AppleEvent to myself with a Pascal string parameter and using the default idle function. pEventID ==> The event to be sent. pValue ==> The Str255 to be sent. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAETellSelfToSetStr255Property(const DescType pPropType,Str255 pValue){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. OSStatus anError = noErr; if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(kAECoreSuite,kAESetData,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pPropType, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); if (noErr == anError) { anError = AEPutParamPtr(&tAppleEvent, keyAEData, typePString, pValue, pValue[0] + 1); if (noErr == anError) anError = MoreAESendEventNoReturnValue(gAEIdleUPP, &tAppleEvent); } } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } return anError;} // MoreAETellSelfToSetStr255Property/******************************************************************************** Send a set data (kAESetData) AppleEvent to myself with a CFStringRef parameter and using the default idle function. pEventID ==> The event to be sent. pValue ==> The CFString to be sent. RESULT CODES ____________ noErr 0 No error and any other error that can be returned by AESend or the handler in the application that gets the event. ____________*/pascal OSStatus MoreAETellSelfToSetCFStringRefProperty( const DescType pPropType, const CFStringRef pCFStringRef){ AppleEvent tAppleEvent = {typeNull,NULL}; // If you always init AEDescs, it's always safe to dispose of them. CFIndex length = CFStringGetLength(pCFStringRef); const UniChar* dataPtr = CFStringGetCharactersPtr(pCFStringRef); const UniChar* tempPtr = NULL; OSStatus anError = noErr; if (dataPtr == NULL) { tempPtr = (UniChar*) NewPtr( (Size) (length * sizeof(UniChar)) ); if (NULL == tempPtr) return memFullErr; CFStringGetCharacters(pCFStringRef, CFRangeMake(0,length), (UniChar*) tempPtr); dataPtr = tempPtr; } if (NULL == gAEIdleUPP) gAEIdleUPP = NewAEIdleUPP(MoreAESimpleIdleFunction); anError = MoreAECreateAppleEventSelfTarget(kAECoreSuite,kAESetData,&tAppleEvent); if (noErr == anError) { AEDesc containerObj = {typeNull,NULL}; // start with the null (application) container AEDesc propertyObject = {typeNull,NULL}; anError = MoreAEOCreatePropertyObject(pPropType, &containerObj, &propertyObject); if (noErr == anError) { anError = AEPutParamDesc(&tAppleEvent, keyDirectObject, &propertyObject); MoreAEDisposeDesc(&propertyObject); if (noErr == anError) { anError = AEPutParamPtr(&tAppleEvent, keyAEData, typeUnicodeText, dataPtr, (Size) (length * sizeof(UniChar)) ); if (noErr == anError) anError = MoreAESendEventNoReturnValue(gAEIdleUPP, &tAppleEvent); } } MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them } if (NULL != tempPtr) DisposePtr((Ptr) tempPtr); return anError;} // MoreAETellSelfToSetCFStringRefProperty//*******************************************************************************#pragma mark ==> Misc. AE utility functions *//*******************************************************************************// Appends each of the items in pSourceList to the pDestList.pascal OSStatus MoreAEAppendListToList(const AEDescList* pSourceList, AEDescList* pDestList){ OSStatus anError; AEKeyword junkKeyword; SInt32 listCount; SInt32 listIndex; AEDesc thisValue; assert(pSourceList != NULL); assert(pDestList != NULL); anError = AECountItems(pSourceList, &listCount); if (noErr == anError) { for (listIndex = 1; listIndex <= listCount; listIndex++) { MoreAENullDesc(&thisValue); anError = AEGetNthDesc(pSourceList, listIndex, typeWildCard, &junkKeyword, &thisValue); if (noErr == anError) { anError = AEPutDesc(pDestList, 0, &thisValue); } MoreAEDisposeDesc(&thisValue); if (noErr != anError) { break; } } } return anError;}//end MoreAEAppendListToList//*******************************************************************************// This routine takes a result descriptor and an error.// If there is a result to add to the reply it makes sure the reply isn't// NULL itself then adds the error to the reply depending on the error// and the type of result.pascal OSStatus MoreAEMoreAESetReplyErrorNumber (OSErr pOSErr, AppleEvent* pAEReply){ OSStatus anError = noErr; if (pAEReply->dataHandle) { if (!MoreAssertPCG (pAEReply->descriptorType == typeAppleEvent)) anError = paramErr; else anError = AEPutParamPtr (pAEReply,keyErrorNumber,typeShortInteger,&pOSErr,sizeof(pOSErr)); } return anError;}//end MoreAEMoreAESetReplyErrorNumber//*******************************************************************************// This routine takes a result descriptor, a reply descriptor and an error.// If there is a result to add to the reply it makes sure the reply isn't// NULL itself then adds the result to the reply depending on the error// and the type of result.pascal OSStatus MoreAEAddResultToReply(const AEDesc* pResult, AEDesc* pAEReply, const OSErr pError){ OSStatus anError; // Check that the pAEReply is not NULL and there is a result to put in it if (typeNull == pAEReply->descriptorType || typeNull == pResult->descriptorType) return (pError); if (noErr == pError) anError = AEPutParamDesc(pAEReply, keyDirectObject, pResult); else { switch (pResult->descriptorType) { case typeInteger: anError = AEPutParamDesc(pAEReply, keyErrorNumber, pResult); break; case typeChar: anError = AEPutParamDesc(pAEReply, keyErrorString, pResult); break; default: anError = errAETypeError; } if (noErr == anError) anError = pError; // Don't loose that error } return (anError);}//end MoreAEAddResultToReply//*******************************************************************************// Name: MoreAEGotRequiredParams// Function: Checks that all parameters defined as 'required' have been readpascal OSStatus MoreAEGotRequiredParams(const AppleEvent* pAppleEventPtr){ DescType returnedType; Size actualSize; OSStatus anError; // look for the keyMissedKeywordAttr, just to see if it's there anError = AEGetAttributePtr(pAppleEventPtr, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); switch (anError) { case errAEDescNotFound: // attribute not there means we anError = noErr; // got all required parameters. break; case noErr: // attribute there means missed anError = errAEParamMissed; // at least one parameter. break; // default: pass on unexpected error in looking for the attribute } return (anError);} // GotReqiredParams/******************************************************************************** Takes a reply event checks it for any errors that may have been returned by the event handler. A simple function, in that it only returns the error number. You can often also extract an error string and three other error parameters from a reply event. Also see: IM:IAC for details about returned error strings. AppleScript developer release notes for info on the other error parameters. pAEReply ==> The reply event to be checked. RESULT CODES ____________ noErr 0 No error ???? ?? Pretty much any error, depending on what the event handler returns for it's errors.*/pascal OSStatus MoreAEGetHandlerError(const AppleEvent* pAEReply){ OSStatus anError = noErr; OSErr handlerErr; DescType actualType; long actualSize; if ( pAEReply->descriptorType != typeNull ) // there's a reply, so there may be an error { OSErr getErrErr = noErr; getErrErr = AEGetParamPtr( pAEReply, keyErrorNumber, typeShortInteger, &actualType, &handlerErr, sizeof( OSErr ), &actualSize ); if ( getErrErr != errAEDescNotFound ) // found an errorNumber parameter { anError = handlerErr; // so return it's value } } return anError;}//end MoreAEGetHandlerError/******************************************************************************** Get the class and ID from an AppleEvent. pAppleEvent ==> The event to get the class and ID from. pAEEventClass output: The event's class. pAEEventID output: The event's ID. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone errAEDescNotFound -1701 Descriptor record was not found errAENotAEDesc -1704 Not a valid descriptor record errAEReplyNotArrived -1718 Reply has not yet arrived */ pascal OSStatus MoreAEExtractClassAndID( const AppleEvent* pAppleEvent, AEEventClass* pAEEventClass, AEEventID* pAEEventID ){ DescType actualType; Size actualSize; OSStatus anError; anError = AEGetAttributePtr( pAppleEvent, keyEventClassAttr, typeType, &actualType, pAEEventClass, sizeof( pAEEventClass ), &actualSize ); if ( noErr == anError ) { anError = AEGetAttributePtr( pAppleEvent, keyEventIDAttr, typeType, &actualType, pAEEventID, sizeof( pAEEventID ), &actualSize ); } return ( anError );}//end ExtractClassAndID/******************************************************************************** A very simple idle function. It simply ignors any event it receives, returns 30 for the sleep time and NULL for the mouse region. Your application should supply an idle function that handles any events it might receive. This is especially important if your application has any windows. Also see: IM:IAC for details about idle functions. Pending Update Perils technote for more about handling low-level events.*/ pascal Boolean MoreAESimpleIdleFunction( EventRecord* event, long* sleepTime, RgnHandle* mouseRgn ){#pragma unused( event ) *sleepTime = 30; *mouseRgn = NULL; return ( false );}//end MoreAESimpleIdleFunction/******************************************************************************** Is the Apple Event Manager present. RESULT CODES ____________ true The Apple Event Manager is present false It isn't*/pascal Boolean MoreAEHasAppleEvents(void){ static long gHasAppleEvents = kFlagNotSet; if ( gHasAppleEvents == kFlagNotSet ) { long response; if ( Gestalt( gestaltAppleEventsAttr, &response ) == noErr ) gHasAppleEvents = ( response & (1L << gestaltAppleEventsPresent) ) != 0; } return (gHasAppleEvents != 0);}//end MoreAEHasAppleEvents//*******************************************************************************// Did this AppleEvent come from the Finder?pascal OSStatus MoreAEIsSenderFinder (const AppleEvent* pAppleEvent, Boolean* pIsFinder){ OSStatus anError = noErr; DescType actualType; ProcessSerialNumber senderPSN; Size actualSize; if (!MoreAssertPCG (pAppleEvent && pIsFinder)) return paramErr; if (!MoreAssertPCG (pAppleEvent->descriptorType == typeAppleEvent)) return paramErr; if (!MoreAssertPCG (pAppleEvent->dataHandle)) return paramErr; anError = AEGetAttributePtr (pAppleEvent, keyAddressAttr, typeProcessSerialNumber, &actualType, (Ptr) &senderPSN, sizeof (senderPSN), &actualSize); if (MoreAssertPCG (noErr == anError)) { if (!MoreAssertPCG (actualType == typeProcessSerialNumber)) anError = paramErr; else if (!MoreAssertPCG (actualSize == sizeof (senderPSN))) anError = paramErr; else { ProcessInfoRec processInfo; if (!(anError = MoreProcGetProcessInformation (&senderPSN,&processInfo))) { *pIsFinder = ( processInfo.processSignature == kFinderProcessSignature && processInfo.processType == kFinderProcessType); } } } return anError;}//end MoreAEIsSenderFinder//*******************************************************************************// This routine returns true if and only if pAEDesc is the "missing value" value.pascal Boolean MoreAEIsMissingValue(const AEDesc* pAEDesc){ DescType missing; return (pAEDesc->descriptorType == typeType) && (AEGetDescDataSize(pAEDesc) == sizeof(missing)) && (AEGetDescData(pAEDesc, &missing, sizeof(missing)) == noErr) && (missing == cMissingValue);}//end MoreAEIsMissingValue//*******************************************************************************// This routine creates a descriptor that represents the missing value.pascal OSStatus MoreAECreateMissingValue(AEDesc* pAEDesc){ const static DescType missingValue = cMissingValue; return AECreateDesc(typeType, &missingValue, sizeof(missingValue), pAEDesc);}//end MoreAECreateMissingValue</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/QISA/listing7.html%3Fid%3DDTS10000714-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/QISA/listing7.html%3Fid%3DDTS10000714-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/QISA/listing7.html%3Fid%3DDTS10000714-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>