home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!firstclass.com!user
- From: MScott@FirstClass.COM (M. Scott Marcy)
- Newsgroups: comp.sys.mac.programmer
- Subject: Apple Events reply problem
- Message-ID: <MScott-120892103239@firstclass.com>
- Date: 12 Aug 92 16:35:33 GMT
- Sender: news@csn.org (news)
- Followup-To: comp.sys.mac.programmer
- Organization: First Class Systems, Inc.
- Lines: 90
- Nntp-Posting-Host: firstclass.com
-
- Hi,
-
- Well, I'm just adding support for AppleEvents to my program, and I need
- to reply to the open document event under certain circumstances (I can
- only open one document at a time). I want to send an error string back
- to the source application, so I followed the procedures in both Inside
- Mac VI (page 6-49, Listing 6-12) and AEObject-Edition Sample (in
- AppleEventCore.c). From all I can tell, I'm doing exactly the same
- thing, but my call to AEPutParamPtr/Desc returns an error -1704
- (errAENotAEDesc). I checked the reply record, which contains a 'null'
- descriptor. All the sample code shows that I should just call
- AEPutParamXXX to store my error string in the reply record--no other
- setup or initialization of the reply record is required.
-
- What gives? I've looked everywhere I can think of on this one and
- haven't found any example other than adding the string directly to the
- reply event given to the event handler.
-
- BTW: I've tried both AEPutParamPtr (as in the examples) and
- AEPutParamDesc, both with the same result. The code below has the
- AEPutParamDesc version.
-
-
- Scott Marcy
- First Class Systems, Inc.
- ALink: FIRST.CLASS
- InterNET: MScott@FirstClass.COM (Preferred)
-
- ==========================================================================
-
- Here's the code from my open document handler. The CHECK, FAIL,
- ERR_HANDLER stuff is for collecting and handling errors. Everything else
- should be (relatively) standard.
-
- pascal OSErr miae_open_doc(AppleEvent *event, AppleEvent *reply, long ref)
- { ERR_HEADER
- #pragma unused (ref)
- Boolean empty, have_list = FALSE, have_desc = FALSE;
- AEDescList doc_list;
- AEDesc desc;
- AEKeyword keyword; /* ignored */
- DescType type; /* ignored */
- Size size; /* ignored */
- long num_items;
- FSSpec file_spec;
- Str255 err_str;
- Str63 name;
- short wd;
-
- /* Get the required parameters */
- CHECK(AEGetParamDesc(event, keyDirectObject, typeAEList, &doc_list));
- have_list = TRUE;
-
- /* Make sure there are no more required parameters */
- CHECK(miae_got_all_params(event, &empty));
- if (!empty)
- FAIL(errAEEventNotHandled);
-
- /* Count the number of files sent to us */
- CHECK(AECountItems(&doc_list, &num_items));
-
- /* We can only open one document, otherwise return an error */
- if (num_items > 1) {
- /* Get an error string */
- GetIndString(err_str, rErrorStrings, iMultOpenErr);
- CHECK(AECreateDesc(typeChar, (Ptr) &err_str[1], err_str[0], &desc));
- have_desc = TRUE;
- CHECK(AEPutParamDesc(reply, keyErrorString, &desc));
- CHECK(AEDisposeDesc(&desc)); have_desc = FALSE;
- FAIL(errAEEventNotHandled); }
- else if (num_items == 1) {
- /* Open the one database specified */
- CHECK(AEGetNthPtr(&doc_list, 1, typeFSS, &keyword, &type,
- (Ptr) &file_spec, sizeof(file_spec), &size));
- /* Make a working directory reference for our open routine */
- CHECK(OpenWD(file_spec.vRefNum, file_spec.parID, FCGB_CREATOR, &wd));
- p_to_c_string(file_spec.name, name);
- CHECK(mi_open_database(wd, name, FALSE));
- CHECK(CloseWD(wd)); }
-
- /* Release the document list handle */
- CHECK(AEDisposeDesc(&doc_list)); have_list = FALSE;
-
- ERR_HANDLER
- if (have_list)
- AEDisposeDesc(&doc_list);
- if (have_desc)
- AEDisposeDesc(&desc);
- ERR_HANDLER_END
- } /* End: miae_open_doc */
-