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