From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
Newsgroups: comp.sys.mac.programmer
Subject: Re: appleevents to hypercard
Date: 23 Jul 92 18:09:19 +1200
Followup-To: joshr@kronos.arc.nasa.gov
Distribution: comp.sys.mac.programmer, comp.sys.mac.hypercard
Organization: University of Waikato, Hamilton, New Zealand

In article <1992Jul21.171805.13264@kronos.arc.nasa.gov>, joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91) writes:
> I have included
> sample source code, written in think c 5.02, that I believe shoud
> send the string "hello" to hypercard.

Yeah, but what do you expect HyperCard to do with the string? If you want it
to display it, then you have to send it a complete HyperTalk command to do so,
such as

	answer "hello"

or

	put "hello"

>  I receive a -609 error (connection is invalid) when I get the AESend().

Hm, I can't find error -609 anywhere in my interface files.

> 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.

No, you're right, the signature is WILD. STAK is the file type for HyperCard
stacks.

>
> ---------------- 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,

No, you have to pass the address of a longword containing the signature.
What you've done is typecast the signature itself to a garbage address!

>       sizeof(kHypercardSignature),  &theAddressDesc);
>       // loads into address desciptor
>    FailOSError(myError);

>
>    myError = AECreateAppleEvent(kCoreEventClass, typeChar, &theAddressDesc,

You're creating an event of class "aevt" and ID "TEXT". I don't recall seeing
such an event anywhere in my copy of the AppleEvent Registry. If you want
HyperCard to execute a HyperTalk sequence, you need an event of class "misc"
and ID "dosc" (do script).

>       kAutoGenerateReturnID, kAnyTransactionID, &theAE);
>    FailOSError(myError);
>
>    myError = AEPutParamPtr(&theAE, keyDirectObject, typeChar, "hello", 5);
>    FailOSError(myError);

This part looks fine, except the string should be a valid piece of HyperTalk
for a misc:dosc event. Try replacing the "hello" with either "answer \"hello\""
or "put \"hello\"". On the other hand, if HyperCard reports an error because
it can't understand the message you sent it, then you know the event is
getting through!

[rest of the code deleted, as it's probably OK. :-)]

Lawrence D'Oliveiro                       fone: +64-7-856-2889
Computer Services Dept                     fax: +64-7-838-4066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
Does "future-proof" strike you as a phrase that can be taken two ways?