home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!stanford.edu!kronos.arc.nasa.gov!joshr
- From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
- Subject: hypercard/appleevents
- Message-ID: <1993Jan8.202517.15345@kronos.arc.nasa.gov>
- Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
- Nntp-Posting-Host: mcc2.arc.nasa.gov
- Organization: NASA/ARC Information Sciences Division
- Date: Fri, 8 Jan 1993 20:25:17 GMT
- Lines: 192
-
- Hey all:
- I`ve been working for quite some time now on a program that runs
- concurrently and closely with hypercard.
-
- I would like to send misc/dosc events from hypercard to my app.
- (and vice/versa)
- I have it working from my app to hypercard, but the hypercard
- error messages are not passed back correctly. The notiication manager
- blinks the multifinder icon in top right with the HC icon, but I don't
- think tthere is any other sign that there was an error. The user must
- switch to HC before recieving the error message.
-
- What I would like is
- 1) when my app sends an AE to hypercard, it waits for HC to finish,
- and READS `the result' out of the returned ae. Currently it sends it and
- waits for HC to finish, but does not unload "the result" from the
- reply. In addition, HC does not appear to work any faster in the background
- while processing the AE than any other time. Cant the client somehow give up
- almost all CPU time while waiting for the AE to finish?
-
- 2) To be able to send dosc events to my program. I think I know how
- to send it (using the SendAppleEvent XCMD stack), but I am unclear on the
- TCL half of the receiving. I know that when it comes into the event loop,
- it will be packaged by TCL into a CAppleEvent. But I am
- unclear what to do next. Has anyone written, or know of, a
- dosc handler code for tcl (or straight C?)
-
- I would be happy to share my existing code.
- If anyone is familiar with these issues, and could help me troublewhoot
- this, pls. give me a hand.
-
- joshr@kronos.arc.nasa.gov
-
- PS - email is better for me than News.
-
- Following find Think C code for my "Send Hypercard Script" function
- If someone can see me making some mistakes, I'd be real thankful for
- the tips.
-
-
-
-
- /****************************************************/
- #include "SendToHyp.h"
- #include <Exceptions.h>
- #include "Constants.h"
- #include <TBUtilities.h>
-
- extern CursHandle gWatchCursor;`
- /* Watch cursor for waiting */
-
- Boolean SendToHypercard(char *messageToSend)
- {
- // mostly from Programming for SYS7, p. 145
- // pseudocode:
-
- // 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
-
- AEAddressDesc theAddressDesc;
- AEDesc theResultDescriptor;
- AppleEvent theAE, theReply;
- OSErr myError, sendError;
- TargetID myTarget;
- PortInfoRec myPortInfo;
- DescType actualType, theDescriptorType;
- long eventError, actualSize, theResultSize;
- ProcessSerialNumber process;
- Boolean fSentSuccess = FALSE;
-
- if (FindHypercardProcessNumber(&process) == FALSE)
- return FALSE;
-
-
- // create descriptor of serial number
- myError = AECreateDesc(typeProcessSerialNumber, (Ptr)&process,
- sizeof(process), &theAddressDesc);
- FailOSErr(myError);
-
- // create the apple event
- myError = AECreateAppleEvent(kHypercardMessageEventClass,
- kHypercardMessageEventID,
- &theAddressDesc, kAutoGenerateReturnID,
- kAnyTransactionID, &theAE);
- FailOSErr(myError);
-
- // dispose of descriptor, (which is now copied into the AE ?)
- myError = AEDisposeDesc( &theAddressDesc);
- /* we don't need it anymore */
- FailOSErr(myError);
-
- // put the string in a a ParamPtr
- myError = AEPutParamPtr(&theAE, keyDirectObject, typeChar,
- messageToSend, strlen(messageToSend) );
- FailOSErr(myError);
-
- SetCursor(*gWatchCursor);
- /*** SHOW WATCH CURSOR ***/
-
- //printf("sending\n"); /// ** DEBUGGING
-
- // Send it
- sendError = AESend(&theAE, &theReply,
- kAEWaitReply + kAECanInteract, kAEHighPriority,
- kNoTimeOut, myIdleProc, 0L);
-
- if (sendError) {
- myError = AEDisposeDesc(&theAE);
- FailOSErr(sendError);
- FailOSErr(myError);
- }
- //printf("no send error\n"); /// ** DEBUGGING
-
- myError = AEDisposeDesc(&theAE);
- FailOSErr(myError);
-
- //printf("AEDisposeDesc(&theAE) worked \n"); /// ** DEBUGGING
-
- /*** WORKS TO HERE ****/
- /** GET RESULT FROM HYPERCARD ***/
-
- myError = AEGetParamPtr( &theReply, keyErrorNumber,
- typeChar, &actualType,
- (Ptr)(&eventError), sizeof(eventError), &actualSize);
- if (myError != errAEDescNotFound) {
- // a descriptor was found
- if (myError) {
- myError = AEDisposeDesc( &theReply);
- // SysBeep(1);
- FailOSErr(myError);
-
- } else {
- if (eventError != noErr) {
- myError=AEDisposeDesc( &theReply);
- // SysBeep(1);
- }
- }
- }
-
- myError = AEGetParamDesc(&theReply, keyDirectObject, typeChar,
- &theResultDescriptor);
- if (myError) { /* no direct object exists ! */
- // there is no reply ?
- myError = AEDisposeDesc( &theReply);
- FailOSErr(myError);
- } else {
- // there is a reply !
- myError = AESizeOfParam( &theReply, keyDirectObject,
- &theDescriptorType,
- &theResultSize);
- FailOSErr(myError);
- }
- /***** PUT IT INTO SCRAP -- CRASHES MACHINE if run
- //myError = ZeroScrap();
- // FailOSErr(myError);
-
- //myError = PutScrap( theResultSize, 'TEXT',
- // *theResultDescriptor.dataHandle);
- //FailOSErr(myError);
- *****/
-
-
- /**** appears never loaded ***/
- //myError = AEDisposeDesc(&theResultDescriptor);
- //FailOSErr(myError);
-
- myError = AEDisposeDesc(&theReply);
- FailOSErr(myError);
-
- fSentSuccess = TRUE;
-
-
- SetCursor(&arrow);
- /* Use arrow cursor again */
-
- return fSentSuccess;
- }
-
-
- --
- ----------------------------------
- #include <std/disclaimer.h> Josh Rabinowitz, Mac TCL programmer
- joshr@kronos.arc.nasa.gov
- "Me lost my cookie at the disco." -- Cookie Monster
-