home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 12773 < prev    next >
Encoding:
Text File  |  1992-07-21  |  4.0 KB  |  127 lines

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!mips!swrinde!elroy.jpl.nasa.gov!ames!kronos.arc.nasa.gov!joshr
  2. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: appleevents to hypercard
  5. Summary: how to send appleevents to HC
  6. Keywords: hypercard, appleevents, ppc, high-level events
  7. Message-ID: <1992Jul21.171805.13264@kronos.arc.nasa.gov>
  8. Date: 21 Jul 92 17:18:05 GMT
  9. Sender: wedgingt@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
  10. Followup-To: joshr@kronos.arc.nasa.gov
  11. Distribution: comp.sys.mac.programmer, comp.sys.mac.hypercard
  12. Organization: NASA/ARC Information Sciences Division
  13. Lines: 111
  14. Nntp-Posting-Host: kronos-arclan.arc.nasa.gov
  15.  
  16. Hey netters, josh here again:
  17.  
  18. Well I found some info on how to send appleevents to hypercard.  Turns out
  19. there is a new hypercard handler for appleevents, so it should be pretty easy
  20. on that end.  I have been having some troublecreating the appleevnt to
  21. send though, perhaps someone could give me a hand.  I have included
  22. sample source code, written in think c 5.02, that I believe shoud
  23. send the string "hello" to hypercard.  I receive a -609 error (connection is
  24. invalid) when I get the AESend().  
  25.  
  26. If you have any tips,please help.  I believe part of the problem may be
  27. that Im not sure if hypercard's signature is STAK or WILD (or is it something
  28. else?), and i'm not sure about the aetype and just how to load the AEAddress
  29. descriptor.
  30.  
  31. ---------------- following is attempted test code ------------
  32. #include <AppleEvents.h>
  33. #include <stdio.h>
  34.  
  35.  
  36. #define kHypercardSignature 'WILD'
  37.  
  38. #define FailOSError(value) if(value){printf("OSError %ld\n", (long)value);exit(1);}
  39.  
  40. pascal OSErr myEventHandler(AppleEvent *event, AppleEvent *reply, long ref);
  41. void main(void);
  42. void unneeded(void);
  43. pascal Boolean myIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle mouseRgn);
  44.  
  45. void main(void) 
  46. {
  47.   // from Programming for SYS7, p. 145
  48.    // pseudocode:
  49.    
  50.    // determine target address using PPCBrowser() or GetNextProcess() and GetProcessInformation()
  51.    
  52.    // create address descriptor from above info
  53.    
  54.    // create apple event with AECreateAppleEvent() and pass it address descriptor
  55.    //  use AEManager to add descriptors with AEPutParamPtr or AEPutParamDesc
  56.    
  57.    // call AESend
  58.    // check for errors
  59.    // dispose of copies of descriptor records
  60.    // process the AEReply
  61.    
  62.    // need appleeventhandler on the other side.
  63.    
  64.    
  65.    AEDesc theAddressDesc;
  66.    AppleEvent theAE, theReply;
  67.    OSErr myError, sendError;
  68.    
  69.    
  70.    printf("PRINTF\n");
  71.    
  72.    myError = AECreateDesc(typeApplSignature, (Ptr)kHypercardSignature, 
  73.       sizeof(kHypercardSignature),  &theAddressDesc);  
  74.       // loads into address desciptor
  75.    FailOSError(myError);
  76.    
  77.    myError = AECreateAppleEvent(kCoreEventClass, typeChar, &theAddressDesc, 
  78.       kAutoGenerateReturnID, kAnyTransactionID, &theAE); 
  79.    FailOSError(myError);
  80.       
  81.    myError = AEPutParamPtr(&theAE, keyDirectObject, typeChar, "hello", 5);
  82.    FailOSError(myError);
  83.    
  84.    sendError = AESend(&theAE, &theReply, kAEQueueReply, kAENormalPriority, 
  85.       kNoTimeOut, myIdleProc, 0L);
  86.    myError = AEDisposeDesc(&theAE);
  87.    if (sendError) {
  88.       myError = AEDisposeDesc( &theReply);
  89.       SysBeep(1);
  90.       FailOSError(myError);
  91.       FailOSError(sendError);
  92.    }
  93.    FailOSError(myError);
  94.  
  95.   
  96. pascal Boolean myIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle mouseRgn)
  97. {
  98.    EventRecord testEvent;
  99.    Boolean gotKbd;
  100.    char key;
  101.    
  102.    gotKbd = GetOSEvent(keyDownMask, &testEvent);
  103.    
  104.    if (gotKbd) {
  105.       key = testEvent.message & charCodeMask;
  106.       if ( (key == '.') && (testEvent.modifiers & cmdKey) )
  107.          return TRUE;
  108.    }
  109.    switch(theEvent->what) {
  110.       case nullEvent:
  111.       break;
  112.    }
  113.    return FALSE;
  114. }
  115.  
  116.  
  117. ------------
  118. HELP  ?
  119. joshr@kronos.arc.nasa.gov
  120.  
  121. -- 
  122. ----------------------------------
  123. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  124. joshr@kronos.arc.nasa.gov
  125. "Why is it that we drive on parkways and park in driveways?" - self
  126.