home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21036 < prev    next >
Encoding:
Text File  |  1993-01-08  |  6.5 KB  |  212 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!stanford.edu!kronos.arc.nasa.gov!joshr
  3. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  4. Subject: appleevents
  5. Message-ID: <1993Jan8.220823.17606@kronos.arc.nasa.gov>
  6. Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
  7. Nntp-Posting-Host: kronos-ethernet.arc.nasa.gov
  8. Organization: NASA/ARC Information Sciences Division
  9. Date: Fri, 8 Jan 1993 22:08:23 GMT
  10. Lines: 200
  11.  
  12.  
  13. Hey all:
  14. I`ve been working for quite some time now on a program that runs
  15. concurrently and closely with hypercard.
  16.  
  17. I would like to send misc/dosc events from hypercard to my app.
  18. (and vice/versa)
  19. I have it working from my app to hypercard, but the hypercard
  20. error messages are not passed back correctly.  The notiication manager
  21. blinks the multifinder icon in top right with the HC icon, but I don't
  22. think tthere is any other sign that there was an error.  The user must
  23. switch to HC before recieving the error message.
  24.  
  25. What I would like is
  26. 1) when my app sends an AE to hypercard, it waits for HC to finish,
  27. and READS `the result' out of the returned ae.  Currently it sends it and
  28. waits for HC to finish, but does not unload "the result" from the
  29. reply.  In addition, HC does not appear to work any faster in the background
  30. while processing the AE than any other time. Cant the client somehow give up
  31. almost all CPU time while waiting for the AE to finish?
  32.  
  33. 2) To be able to send dosc events to my program.  I think I know how
  34. to send it (using the SendAppleEvent XCMD stack), but I am unclear on the
  35. TCL half of the receiving.  I know that when it comes into the event loop,
  36. it will be packaged by TCL into a CAppleEvent.  But I am
  37. unclear what to do next.  Has anyone written, or know of, a
  38. dosc handler code for tcl (or straight C?)
  39.  
  40. I would be happy to share my existing code.
  41. If anyone is familiar with these issues, and could help me troublewhoot
  42. this, pls. give me a hand.
  43.  
  44. joshr@kronos.arc.nasa.gov
  45.  
  46. PS - email is better for me than News.
  47.  
  48. Following find Think C code for my "Send Hypercard Script" function
  49. If someone can see me making some mistakes, I'd be real thankful for
  50. the tips.
  51.  
  52.  
  53.  
  54.  
  55. /****************************************************/
  56. #include "SendToHyp.h"
  57. #include <Exceptions.h>
  58. #include "Constants.h"
  59. #include <TBUtilities.h>
  60.  
  61. extern CursHandle            gWatchCursor;`
  62. /* Watch cursor for waiting            */
  63.  
  64. Boolean SendToHypercard(char *messageToSend) 
  65. {
  66.   // mostly from Programming for SYS7, p. 145
  67.    // pseudocode:
  68.    
  69.    //   GetProcessInformation()
  70.    // create address descriptor from above info
  71.    
  72.    // create apple event with AECreateAppleEvent() and 
  73.    // pass it address descriptor
  74.    //  use AEManager to add descriptors with AEPutParamPtr or AEPutParamDesc
  75.    // call AESend
  76.    // check for errors
  77.    // dispose of copies of descriptor records
  78.    // process the AEReply
  79.    
  80.    AEAddressDesc     theAddressDesc;
  81.    AEDesc        theResultDescriptor;
  82.    AppleEvent     theAE, theReply;
  83.    OSErr         myError, sendError;
  84.    TargetID     myTarget;
  85.    PortInfoRec    myPortInfo;
  86.    DescType     actualType, theDescriptorType;
  87.    long         eventError, actualSize, theResultSize;
  88.    ProcessSerialNumber process;
  89.    Boolean fSentSuccess = FALSE;
  90.    
  91.    if (FindHypercardProcessNumber(&process) == FALSE) 
  92.        return FALSE;
  93.  
  94.        
  95.        // create descriptor of serial number
  96.        myError = AECreateDesc(typeProcessSerialNumber, (Ptr)&process, 
  97.           sizeof(process), &theAddressDesc);
  98.        FailOSErr(myError);
  99.     
  100.         // create the apple event
  101.        myError = AECreateAppleEvent(kHypercardMessageEventClass, 
  102.                kHypercardMessageEventID, 
  103.           &theAddressDesc, kAutoGenerateReturnID,
  104.                kAnyTransactionID, &theAE); 
  105.        FailOSErr(myError);
  106.        
  107.        // dispose of descriptor, (which is now copied into the AE ?)
  108.        myError = AEDisposeDesc( &theAddressDesc);   
  109.        /* we don't need it anymore */
  110.        FailOSErr(myError);
  111.           
  112.        // put the string in a a ParamPtr
  113.        myError = AEPutParamPtr(&theAE, keyDirectObject, typeChar, 
  114.           messageToSend, strlen(messageToSend) );
  115.        FailOSErr(myError);
  116.        
  117.        SetCursor(*gWatchCursor);
  118.        /*** SHOW WATCH CURSOR ***/
  119.        
  120.        //printf("sending\n");    /// ** DEBUGGING
  121.        
  122.        // Send it 
  123.        sendError = AESend(&theAE, &theReply, 
  124.            kAEWaitReply + kAECanInteract, kAEHighPriority, 
  125.           kNoTimeOut, myIdleProc, 0L);
  126.        
  127.        if (sendError) {
  128.           myError = AEDisposeDesc(&theAE);
  129.           FailOSErr(sendError);
  130.           FailOSErr(myError);
  131.        }
  132.        //printf("no send error\n");    /// ** DEBUGGING
  133.     
  134.        myError = AEDisposeDesc(&theAE);
  135.        FailOSErr(myError);
  136.        
  137.        //printf("AEDisposeDesc(&theAE) worked \n");    /// ** DEBUGGING
  138.     
  139.        /*** WORKS TO HERE ****/
  140.        /** GET RESULT FROM HYPERCARD ***/
  141.        
  142.        myError = AEGetParamPtr( &theReply, keyErrorNumber, 
  143.               typeChar, &actualType,
  144.           (Ptr)(&eventError), sizeof(eventError), &actualSize);
  145.        if (myError != errAEDescNotFound) {
  146.            // a descriptor was found
  147.           if (myError) {
  148.              myError = AEDisposeDesc( &theReply);
  149.              // SysBeep(1);
  150.                    FailOSErr(myError);
  151.  
  152.           } else {
  153.              if (eventError != noErr) {
  154.                 myError=AEDisposeDesc( &theReply);
  155.                 // SysBeep(1);
  156.              }
  157.           }
  158.        }
  159.     
  160.        myError = AEGetParamDesc(&theReply, keyDirectObject, typeChar, 
  161.           &theResultDescriptor);
  162.        if (myError) { /* no direct object exists ! */
  163.            // there is no reply ?
  164.           myError = AEDisposeDesc( &theReply);
  165.           FailOSErr(myError);
  166.        } else {
  167.            // there is a reply !
  168.            myError = AESizeOfParam( &theReply, keyDirectObject,
  169.                       &theDescriptorType,
  170.               &theResultSize);
  171.            FailOSErr(myError);
  172.         }
  173.            /*****  PUT IT INTO SCRAP -- CRASHES MACHINE if run
  174.            //myError = ZeroScrap();
  175.            // FailOSErr(myError);
  176.            
  177.            //myError = PutScrap( theResultSize, 'TEXT', 
  178.                //    *theResultDescriptor.dataHandle);
  179.            //FailOSErr(myError);
  180.            *****/
  181.         
  182.         
  183.         /**** appears never loaded ***/   
  184.        //myError = AEDisposeDesc(&theResultDescriptor);
  185.        //FailOSErr(myError);
  186.        
  187.        myError = AEDisposeDesc(&theReply);
  188.        FailOSErr(myError);
  189.        
  190.            fSentSuccess = TRUE;      
  191.     
  192.     
  193.         SetCursor(&arrow);
  194.                 /* Use arrow cursor again        */
  195.  
  196.     return fSentSuccess;
  197. }
  198.  
  199.  
  200. -- 
  201. ----------------------------------
  202. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  203. joshr@kronos.arc.nasa.gov
  204. "Me lost my cookie at the disco." -- Cookie Monster
  205.  
  206.  
  207. -- 
  208. ----------------------------------
  209. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  210. joshr@kronos.arc.nasa.gov
  211. "Me lost my cookie at the disco." -- Cookie Monster
  212.