home *** CD-ROM | disk | FTP | other *** search
- #include "SendAEs.h"
-
- /* This routine will create a targetDesc using the apps signature */
- static OSErr GetTargetFromSignature (OSType processSig, AEAddressDesc *targetDesc)
- {
- return( AECreateDesc(typeApplSignature, (Ptr)&processSig, sizeof(processSig), targetDesc) );
- }
-
- static void SendDocsToProc ( AEDescList *fileList, AEEventClass inClass, AEEventID inID, OSType inProcID )
- {
- OSErr err = noErr;
- AEAddressDesc theTarget;
- AppleEvent openDocAE, replyAE;
-
- err = GetTargetFromSignature ( inProcID, &theTarget );
- if ( err == noErr ) {
- /* Next we create the Apple event that will later get sent. */
- err = AECreateAppleEvent ( inClass, inID, &theTarget,
- kAutoGenerateReturnID, kAnyTransactionID, &openDocAE );
-
- if ( err == noErr ) {
- /* Now add the fileDescList to the openDocAE */
- err = AEPutParamDesc ( &openDocAE, keyDirectObject, fileList );
-
- if ( err == noErr ) {
- /* and finally send the event */
- /* Since we are sending to ourselves, no need for reply. */
- err = AESend ( &openDocAE, &replyAE, kAEWaitReply + kAECanInteract,
- kAENormalPriority, 3600, NULL, NULL );
- }
-
- /* Dispose of the fileList descriptor
- We do this instead of the caller since it needs to be done
- before disposing the AEVT
- */
- err = AEDisposeDesc ( fileList );
-
- /* and of course dispose of the openDoc AEVT itself*/
- err = AEDisposeDesc ( &openDocAE );
- }
-
- /* and of course dispose of the Target */
- err = AEDisposeDesc ( &theTarget );
- }
- }
-
- void SendEventToProc ( FSSpecPtr theFileSpec, AEEventClass inClass, AEEventID inID, OSType inProcID )
- {
- OSErr err = noErr;
- AEDescList fileList;
-
- /* Create the descList to hold the list of files */
- err = AECreateList ( NULL, 0, false, &fileList );
-
- if ( err == noErr ) {
- /* Add the FSSpec to the list */
- err = AEPutPtr ( &fileList, 0, typeFSS, theFileSpec, sizeof ( FSSpec ));
-
- /* Now call the real gut level routine to do the dirty work*/
- if ( err == noErr )
- SendDocsToProc ( &fileList, inClass, inID, inProcID );
- }
- }
-