home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / PostScript OSA / SendAEs.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  2.0 KB  |  64 lines

  1. #include "SendAEs.h"
  2.  
  3. /* This routine will create a targetDesc using the apps signature */
  4. static OSErr GetTargetFromSignature (OSType processSig, AEAddressDesc *targetDesc)
  5. {
  6.     return( AECreateDesc(typeApplSignature, (Ptr)&processSig, sizeof(processSig), targetDesc) );
  7. }
  8.  
  9. static void SendDocsToProc ( AEDescList *fileList, AEEventClass inClass, AEEventID inID, OSType inProcID ) 
  10. {
  11.     OSErr            err = noErr;
  12.     AEAddressDesc    theTarget;
  13.     AppleEvent        openDocAE, replyAE;
  14.  
  15.     err = GetTargetFromSignature ( inProcID, &theTarget );
  16.     if ( err == noErr ) {
  17.         /* Next we create the Apple event that will later get sent. */
  18.         err = AECreateAppleEvent ( inClass, inID, &theTarget, 
  19.                                 kAutoGenerateReturnID, kAnyTransactionID, &openDocAE );
  20.  
  21.         if ( err == noErr ) {
  22.             /* Now add the fileDescList to the openDocAE */
  23.             err = AEPutParamDesc ( &openDocAE, keyDirectObject, fileList );
  24.  
  25.             if ( err == noErr ) {
  26.             /*    and finally send the event */
  27.             /*    Since we are sending to ourselves, no need for reply. */
  28.                 err = AESend ( &openDocAE, &replyAE, kAEWaitReply + kAECanInteract,
  29.                             kAENormalPriority, 3600, NULL, NULL );
  30.                 }
  31.  
  32.         /*    Dispose of the fileList descriptor
  33.             We do this instead of the caller since it needs to be done
  34.             before disposing the AEVT
  35.         */
  36.             err = AEDisposeDesc ( fileList );
  37.  
  38.         /*    and of course dispose of the openDoc AEVT itself*/
  39.             err = AEDisposeDesc ( &openDocAE );
  40.             }
  41.  
  42.     /*    and of course dispose of the Target */
  43.         err = AEDisposeDesc ( &theTarget );
  44.         }
  45.     }
  46.  
  47. void SendEventToProc ( FSSpecPtr theFileSpec, AEEventClass inClass, AEEventID inID, OSType inProcID ) 
  48. {
  49.     OSErr        err = noErr;
  50.     AEDescList    fileList;
  51.     
  52. /*    Create the descList to hold the list of files */
  53.     err = AECreateList ( NULL, 0, false, &fileList );
  54.  
  55.     if ( err == noErr ) {
  56.     /*    Add the FSSpec to the list */
  57.         err = AEPutPtr ( &fileList, 0, typeFSS, theFileSpec, sizeof ( FSSpec ));
  58.  
  59.     /*    Now call the real gut level routine to do the dirty work*/
  60.         if ( err == noErr )
  61.             SendDocsToProc ( &fileList, inClass, inID, inProcID );
  62.         }
  63.     }
  64.