home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13885 < prev    next >
Encoding:
Text File  |  1992-08-12  |  3.6 KB  |  103 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!firstclass.com!user
  2. From: MScott@FirstClass.COM (M. Scott Marcy)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Apple Events reply problem
  5. Message-ID: <MScott-120892103239@firstclass.com>
  6. Date: 12 Aug 92 16:35:33 GMT
  7. Sender: news@csn.org (news)
  8. Followup-To: comp.sys.mac.programmer
  9. Organization: First Class Systems, Inc.
  10. Lines: 90
  11. Nntp-Posting-Host: firstclass.com
  12.  
  13. Hi,
  14.  
  15. Well, I'm just adding support for AppleEvents to my program, and I need
  16. to reply to the open document event under certain circumstances (I can
  17. only open one document at a time). I want to send an error string back
  18. to the source application, so I followed the procedures in both Inside
  19. Mac VI (page 6-49, Listing 6-12) and AEObject-Edition Sample (in
  20. AppleEventCore.c). From all I can tell, I'm doing exactly the same
  21. thing, but my call to AEPutParamPtr/Desc returns an error -1704
  22. (errAENotAEDesc). I checked the reply record, which contains a 'null'
  23. descriptor. All the sample code shows that I should just call
  24. AEPutParamXXX to store my error string in the reply record--no other
  25. setup or initialization of the reply record is required.
  26.  
  27. What gives? I've looked everywhere I can think of on this one and
  28. haven't found any example other than adding the string directly to the
  29. reply event given to the event handler.
  30.  
  31. BTW: I've tried both AEPutParamPtr (as in the examples) and
  32. AEPutParamDesc, both with the same result. The code below has the
  33. AEPutParamDesc version.
  34.  
  35.  
  36. Scott Marcy
  37. First Class Systems, Inc.
  38. ALink:    FIRST.CLASS
  39. InterNET: MScott@FirstClass.COM            (Preferred)
  40.  
  41. ==========================================================================
  42.  
  43. Here's the code from my open document handler. The CHECK, FAIL,
  44. ERR_HANDLER stuff is for collecting and handling errors. Everything else
  45. should be (relatively) standard.
  46.  
  47. pascal OSErr miae_open_doc(AppleEvent *event, AppleEvent *reply, long ref)
  48. { ERR_HEADER
  49. #pragma unused (ref)
  50. Boolean            empty, have_list = FALSE, have_desc = FALSE;
  51. AEDescList        doc_list;
  52. AEDesc            desc;
  53. AEKeyword        keyword;        /* ignored */
  54. DescType        type;            /* ignored */
  55. Size            size;            /* ignored */
  56. long            num_items;
  57. FSSpec            file_spec;
  58. Str255            err_str;
  59. Str63            name;
  60. short            wd;
  61.  
  62.     /* Get the required parameters */
  63.     CHECK(AEGetParamDesc(event, keyDirectObject, typeAEList, &doc_list));
  64.     have_list = TRUE;
  65.  
  66.     /* Make sure there are no more required parameters */
  67.     CHECK(miae_got_all_params(event, &empty));
  68.     if (!empty)
  69.         FAIL(errAEEventNotHandled);
  70.  
  71.     /* Count the number of files sent to us */
  72.     CHECK(AECountItems(&doc_list, &num_items));
  73.  
  74.     /* We can only open one document, otherwise return an error */
  75.     if (num_items > 1) {
  76.         /* Get an error string */
  77.         GetIndString(err_str, rErrorStrings, iMultOpenErr);
  78.         CHECK(AECreateDesc(typeChar, (Ptr) &err_str[1], err_str[0], &desc));
  79.         have_desc = TRUE;
  80.         CHECK(AEPutParamDesc(reply, keyErrorString, &desc));
  81.         CHECK(AEDisposeDesc(&desc)); have_desc = FALSE;
  82.         FAIL(errAEEventNotHandled); }
  83.     else if (num_items == 1) {
  84.         /* Open the one database specified */
  85.         CHECK(AEGetNthPtr(&doc_list, 1, typeFSS, &keyword, &type,
  86.                         (Ptr) &file_spec, sizeof(file_spec), &size));
  87.         /* Make a working directory reference for our open routine */
  88.         CHECK(OpenWD(file_spec.vRefNum, file_spec.parID, FCGB_CREATOR, &wd));
  89.         p_to_c_string(file_spec.name, name);
  90.         CHECK(mi_open_database(wd, name, FALSE));
  91.         CHECK(CloseWD(wd)); }
  92.  
  93.     /* Release the document list handle */
  94.     CHECK(AEDisposeDesc(&doc_list)); have_list = FALSE;
  95.  
  96. ERR_HANDLER
  97.     if (have_list)
  98.         AEDisposeDesc(&doc_list);
  99.     if (have_desc)
  100.         AEDisposeDesc(&desc);
  101. ERR_HANDLER_END
  102. } /* End: miae_open_doc */
  103.