From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
Newsgroups: comp.sys.mac.programmer
Subject: appleevents to hypercard
Summary: how to send appleevents to HC
Keywords: hypercard, appleevents, ppc, high-level events
Date: 21 Jul 92 17:18:05 GMT
Followup-To: joshr@kronos.arc.nasa.gov
Distribution: comp.sys.mac.programmer, comp.sys.mac.hypercard
Organization: NASA/ARC Information Sciences Division

Hey netters, josh here again:

Well I found some info on how to send appleevents to hypercard.  Turns out
there is a new hypercard handler for appleevents, so it should be pretty easy
on that end.  I have been having some troublecreating the appleevnt to
send though, perhaps someone could give me a hand.  I have included
sample source code, written in think c 5.02, that I believe shoud
send the string "hello" to hypercard.  I receive a -609 error (connection is
invalid) when I get the AESend().  
 
If you have any tips,please help.  I believe part of the problem may be
that Im not sure if hypercard's signature is STAK or WILD (or is it something
else?), and i'm not sure about the aetype and just how to load the AEAddress
descriptor.

---------------- following is attempted test code ------------
#include <AppleEvents.h>
#include <stdio.h>


#define kHypercardSignature 'WILD'

#define FailOSError(value) if(value){printf("OSError %ld\n", (long)value);exit(1);}

pascal OSErr myEventHandler(AppleEvent *event, AppleEvent *reply, long ref);
void main(void);
void unneeded(void);
pascal Boolean myIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle mouseRgn);

void main(void) 
{
  // from Programming for SYS7, p. 145
   // pseudocode:
   
   // determine target address using PPCBrowser() or GetNextProcess() and GetProcessInformation()
   
   // create address descriptor from above info
   
   // create apple event with AECreateAppleEvent() and pass it address descriptor
   //  use AEManager to add descriptors with AEPutParamPtr or AEPutParamDesc
   
   // call AESend
   // check for errors
   // dispose of copies of descriptor records
   // process the AEReply
   
   // need appleeventhandler on the other side.
   
   
   AEDesc theAddressDesc;
   AppleEvent theAE, theReply;
   OSErr myError, sendError;
   
   
   printf("PRINTF\n");
   
   myError = AECreateDesc(typeApplSignature, (Ptr)kHypercardSignature, 
      sizeof(kHypercardSignature),  &theAddressDesc);  
      // loads into address desciptor
   FailOSError(myError);
   
   myError = AECreateAppleEvent(kCoreEventClass, typeChar, &theAddressDesc, 
      kAutoGenerateReturnID, kAnyTransactionID, &theAE); 
   FailOSError(myError);
      
   myError = AEPutParamPtr(&theAE, keyDirectObject, typeChar, "hello", 5);
   FailOSError(myError);
   
   sendError = AESend(&theAE, &theReply, kAEQueueReply, kAENormalPriority, 
      kNoTimeOut, myIdleProc, 0L);
   myError = AEDisposeDesc(&theAE);
   if (sendError) {
      myError = AEDisposeDesc( &theReply);
      SysBeep(1);
      FailOSError(myError);
      FailOSError(sendError);
   }
   FailOSError(myError);

} 
  
pascal Boolean myIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle mouseRgn)
{
   EventRecord testEvent;
   Boolean gotKbd;
   char key;
   
   gotKbd = GetOSEvent(keyDownMask, &testEvent);
   
   if (gotKbd) {
      key = testEvent.message & charCodeMask;
      if ( (key == '.') && (testEvent.modifiers & cmdKey) )
         return TRUE;
   }
   switch(theEvent->what) {
      case nullEvent:
      break;
   }
   return FALSE;
}


------------
HELP  ?
joshr@kronos.arc.nasa.gov

-- 
----------------------------------
#include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
joshr@kronos.arc.nasa.gov
"Why is it that we drive on parkways and park in driveways?" - self
Newsgroups: comp.sys.mac.programmer