home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-056 < prev    next >
Text File  |  2010-09-21  |  57KB  |  1,589 lines

  1. Received-Date: Sat, 10 Sep 1994 13:05:34 +0200
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: csmp-digest-v3-056
  4. To: csmp-digest@ens.fr
  5. Date: Sat, 10 Sep 1994 13:05:29 +0200 (MET DST)
  6. X-Mailer: ELM [version 2.4 PL23]
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=ISO-8859-1
  9. Content-Transfer-Encoding: 8bit
  10. Errors-To: listman@ens.fr
  11. Reply-To: pottier@clipper.ens.fr
  12. X-Sequence: 61
  13.  
  14. C.S.M.P. Digest             Sat, 10 Sep 94       Volume 3 : Issue 56
  15.  
  16. Today's Topics:
  17.  
  18.         A tool I could REALLY use, written it?
  19.         Async FileMgr Calls
  20.         Future of ASLM
  21.         Review of PowerMac devtools available
  22.         SetDialogDefaultItem() not doing anything!
  23.         Trouble making floating windows work with modeless dialogs
  24.  
  25.  
  26.  
  27. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  28. (pottier@clipper.ens.fr).
  29.  
  30. The digest is a collection of article threads from the internet newsgroup
  31. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  32. regularly and want an archive of the discussions.  If you don't know what a
  33. newsgroup is, you probably don't have access to it.  Ask your systems
  34. administrator(s) for details.  If you don't have access to news, you may
  35. still be able to post messages to the group by using a mail server like
  36. anon.penet.fi (mail help@anon.penet.fi for more information).
  37.  
  38. Each issue of the digest contains one or more sets of articles (called
  39. threads), with each set corresponding to a 'discussion' of a particular
  40. subject.  The articles are not edited; all articles included in this digest
  41. are in their original posted form (as received by our news server at
  42. nef.ens.fr).  Article threads are not added to the digest until the last
  43. article added to the thread is at least two weeks old (this is to ensure that
  44. the thread is dead before adding it to the digest).  Article threads that
  45. consist of only one message are generally not included in the digest.
  46.  
  47. The digest is officially distributed by two means, by email and ftp.
  48.  
  49. If you want to receive the digest by mail, send email to listserv@ens.fr
  50. with no subject and one of the following commands as body:
  51.     help                        Sends you a summary of commands
  52.     subscribe csmp-digest Your Name    Adds you to the mailing list
  53.     signoff csmp-digest            Removes you from the list
  54. Once you have subscribed, you will automatically receive each new
  55. issue as it is created.
  56.  
  57. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  58. Questions related to the ftp site should be directed to
  59. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  60. digest are available there.
  61.  
  62. Also, the digests are available to WAIS users.  To search back issues
  63. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  64. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  65.  
  66.  
  67. -------------------------------------------------------
  68.  
  69. >From Chris Russo <chris@sonicsys.com>
  70. Subject: A tool I could REALLY use, written it?
  71. Date: 24 Aug 1994 16:57:56 GMT
  72. Organization: Sonic Systems, Inc.
  73.  
  74. While tracking down a nasty memory leak yesterday, I thought of something that
  75. would have been REALLY helpful.  What if I patched NewHandle() so that
  76. whenever it was called it would traipse over to the end of my routine and grab
  77. the Debugger info, then tacked it onto the rear of the handle?
  78.  
  79. That way, I could look at all of those loose memory fragments from ZoneRanger
  80. and determine instantly from where they had been allocated.
  81.  
  82. I started working on the thing yesterday, and spent a couple of hours on it.
  83. I wrote patches for NewHandle(), GetHandleSize(), and SetHandleSize().  Those
  84. last two would naturally have to be patched to make the debugging info
  85. transparent to the calling application.
  86.  
  87. Unfortunately, the routines aren't quite working and tend to crash.  More
  88. unfortunately, I don't have the time to keep working on them. :-(
  89.  
  90. If anyone's already written such a patch, <whoops> please let me know how it
  91. went and if I could have it.
  92.  
  93. If anyone would like to take this idea and run with it, by all means do so. 
  94. You can even have the source that I started.  There might be some issues
  95. involving the application's trap dispatch table that I'm not dealing with
  96. properly.  I've never really taken the time to learn that much about it, but
  97. would be happy to learn where I went awry.
  98.  
  99. btw, I have seen the leaks dcmd and don't really like to use it much.  From
  100. ZoneRanger, I can usually tell which memory blocks are useless, but it's hard
  101. to correlate those to the ones captured in leaks.  On top of that, leaks
  102. crashes my version of TMON.
  103.  
  104. Once again, if anyone wants to continue my effort, let me know.
  105.  
  106. - ------------------------------------------------------------------------
  107. Chris Russo                      Macintosh Programmer
  108. Sonic Systems, Inc.              (408) 736-1900 #107
  109. chris@sonicsys.com               NEVER respond to flame bait!
  110.  
  111. +++++++++++++++++++++++++++
  112.  
  113. >From onyxtech@aol.com (OnyxTech)
  114. Date: 26 Aug 1994 17:43:03 -0400
  115. Organization: America Online, Inc. (1-800-827-6364)
  116.  
  117. In article <33fu6k$f5s@news.internex.net>, Chris Russo
  118. <chris@sonicsys.com> writes:
  119.  
  120. >While tracking down a nasty memory leak yesterday, I thought of
  121. >something that would have been REALLY helpful.  What if I patched
  122. >NewHandle() so that whenever it was called it would traipse over to
  123. >the end of my routine and grab the Debugger info, then tacked it onto
  124. >the rear of the handle?
  125. >That way, I could look at all of those loose memory fragments from
  126. >ZoneRanger and determine instantly from where they had been allocated.
  127.  
  128. Mmmm.  There is a version of QC(tm) that has similar leaks detection (you
  129. can use sym files as well) that will follow a native PowerPC upgrade ahead
  130. of it in the pipeline.  We are working on graphical representation of heap
  131. allocations and deletions and hope to create some sort of published
  132. interface so tools like ZoneRanger can use our data to represent more
  133. information to users.  After all, why should we re-create ZoneRanger type
  134. utilities when they've already done all the work.  We just need to help
  135. them get at more information.
  136.  
  137. If you'd like me to keep you (and whomever else is reading this) abreast
  138. of this new version of QC, drop us a line at 'onyxtech@aol.com'.
  139.  
  140. dEVoN Hubbard
  141. Onyx Technology
  142.  
  143. +++++++++++++++++++++++++++
  144.  
  145. >From h+@nada.kth.se (Jon W{tte)
  146. Date: Sat, 27 Aug 1994 15:52:17 +0200
  147. Organization: Royal Institute of Something or other
  148.  
  149. In article <33fu6k$f5s@news.internex.net>,
  150. Chris Russo <chris@sonicsys.com> wrote:
  151.  
  152. >While tracking down a nasty memory leak yesterday, I thought of something that
  153. >would have been REALLY helpful.  What if I patched NewHandle() so that
  154. >whenever it was called it would traipse over to the end of my routine and grab
  155. >the Debugger info, then tacked it onto the rear of the handle?
  156. >
  157. >That way, I could look at all of those loose memory fragments from ZoneRanger
  158. >and determine instantly from where they had been allocated.
  159.  
  160. It's easier to just install the "leaks" MacsBug dcmd. I don't 
  161. know whether it will still work with the new memroy manager 
  162. though. Anyone else know?
  163.  
  164. Another thing you can do is to replace all your calls to 
  165. NewHandle() etc with MyNewHandle() and have non-patches that 
  166. did the tracking work; you could even define MyNewHandle to 
  167. pass source file and line number information using __FILE__ and 
  168. __LINE__. Then when you compile the release version, you just 
  169. define MyNewHandle() to NewHandle().
  170.  
  171. This is great for validating memory as well; you can have a 
  172. validation routine that traverses all of your dynamically 
  173. allocated memory and checks it against a list you keep; if 
  174. something's not checked on the list, you have a leak. If a 
  175. pointer/handle is not on the list, you have a dangling 
  176. pointer/handle.
  177.  
  178. Cheers,
  179.  
  180.                 / h+
  181.  
  182.  
  183. --
  184.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  185.     Not speaking for IBM.
  186.  
  187.  
  188. ---------------------------
  189.  
  190. >From chris-b@cs.auckland.ac.nz (Chris Burns)
  191. Subject: Async FileMgr Calls
  192. Date: Sat, 20 Aug 1994 00:58:02 +1200
  193. Organization: AucklandUniversity:ComputerScience:HMU
  194.  
  195. Hi All,
  196.  
  197. I've been looking into using async file manager calls, so I started
  198. experimenting with an easy one, an indexed _PBHGetVInfoAsync call until
  199. the error returned is nsvErr (no-such-volume: -35). This works perfectly
  200. using sync calls. Things aren't so rosy on the async front tho'.
  201.  
  202. Being in a PowerPC friendly kind of mood (and running on a PM8100/80), I
  203. thought "cool, I'll use UPPs for my completion routine specifiers, and
  204. compile a fat app". This aspect is fine, and in fact, the PowerPC native
  205. version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  206. 68K version however, does not work. The _PBHGetVInfoAsync call returns all
  207. kinds of bogus values instead of nice file manager errors.
  208.  
  209. Here's the entire code:
  210.  
  211.  
  212. ////////////////////////////////////////////
  213. // Chris Burns  ©August 1994
  214. ////////////////////////////////////////////
  215.  
  216. #include <Files.h>
  217.  
  218. ////////////////////////////////////////////
  219.  
  220. typedef struct
  221. {
  222.     HVolumeParam    PB;
  223.     Str255          VolName;
  224.     long            AppA5;
  225. }
  226. VolPBRec,*VolPBPtr;
  227.  
  228. ////////////////////////////////////////////
  229.  
  230. short           gNumDrives;
  231. volatile short  gNumDrivesDone;
  232.  
  233. ////////////////////////////////////////////
  234.  
  235. IOCompletionUPP     gCompletionProcUPP;
  236.  
  237. #if USES68KINLINES
  238. #pragma parameter CompletionProc(__A0)
  239. #endif
  240.  
  241. pascal void CompletionProc(HParmBlkPtr HPB)
  242. {
  243. long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  244.  
  245.     gNumDrivesDone++;
  246.     DebugStr(((VolPBPtr)HPB)->VolName);
  247.  
  248.     SetA5(SavedA5);
  249. }
  250.  
  251. ////////////////////////////////////////////
  252.  
  253. void main(void)
  254. {
  255. OSErr               Err;
  256. VolPBPtr            VPB;
  257.  
  258.     gNumDrives = 0;
  259.     gNumDrivesDone = 0;
  260.     gCompletionProcUPP = NewIOCompletionProc(CompletionProc);
  261.  
  262.     Err = noErr;
  263.  
  264.     while (Err != nsvErr)
  265.     {
  266.         gNumDrives++;
  267.     
  268.         VPB = (VolPBPtr)NewPtrClear(sizeof(VolPBRec));
  269.         if ((VPB == nil) || (MemError() != noErr))
  270.             DebugStr("\pMain: _NewPtrClear(VPB) FAILED");
  271.         
  272.         VPB->PB.ioCompletion = gCompletionProcUPP;
  273.         VPB->PB.ioVolIndex = gNumDrives;
  274.         VPB->PB.ioNamePtr = VPB->VolName;
  275.         VPB->PB.ioVRefNum = 0;
  276.         VPB->AppA5 = SetCurrentA5();
  277.  
  278.         Err = PBHGetVInfoAsync((HParmBlkPtr)VPB);
  279.  
  280.         switch (Err)
  281.         {
  282.             case noErr:
  283.                 break;
  284.  
  285.             case nsvErr:
  286.                 continue;
  287.  
  288.             default:
  289.                 DebugStr("\p_PBHGetVInfoAsync FAILED");
  290.                 break;
  291.         }
  292.     }
  293.  
  294.     while (gNumDrivesDone != gNumDrives);
  295.  
  296.     DisposeRoutineDescriptor(gCompletionProcUPP);
  297. }
  298.  
  299. ////////////////////////////////////////////
  300.  
  301. The:
  302.  
  303. #if USES68KINLINES
  304. #pragma parameter CompletionProc(__A0)
  305. #endif
  306.  
  307. bit was necessary for the 68K version to realize the param block ptr was
  308. in A0 rather than on the stack. I just grabbed it from one of the
  309. Universal Headers because it looked right. It seems to work, and the asm
  310. looks right.
  311.  
  312. The problem seems to be in my CompletionProc. Whatever value D0.w is upon
  313. exit, comes out as the original Err = PBHGetVInfoAsync(); This shouldn't
  314. be so because that error simply tells me if the request was queued ok. For
  315. file manager completion routines THINK Ref 2.0 says "Save and restore all
  316. CPU registers except A0,A1, and D0-D2". My code seems to do this yet
  317. doesn't run correctly.
  318.  
  319. Here's the 68K asm:
  320.  
  321. Hunk:   Kind=HUNK_GLOBAL_CODE  Name="COMPLETIONPROC"(4)  Size=64
  322. 00000000: 4E56 FFF8          LINK      A6,#$FFF8
  323. 00000004: 2D48 FFF8          MOVE.L    A0,$FFF8(A6)
  324. 00000008: 206E FFF8          MOVEA.L   $FFF8(A6),A0
  325. 0000000C: 2028 017A          MOVE.L    $017A(A0),D0
  326. 00000010: C18D               EXG       D0,A5
  327. 00000012: 2D40 FFFC          MOVE.L    D0,$FFFC(A6)
  328. 00000016: 526D 0000          ADDQ.W    #$1,gNumDrivesDone
  329. 0000001A: 206E FFF8          MOVEA.L   $FFF8(A6),A0
  330. 0000001E: 4868 007A          PEA       $007A(A0)
  331. 00000022: ABFF               _DebugStr
  332. 00000024: 202E FFFC          MOVE.L    $FFFC(A6),D0
  333. 00000028: C18D               EXG       D0,A5
  334. 0000002A: 4E5E               UNLK      A6
  335. 0000002C: 4E75               RTS
  336. 0000002E: 8E43 4F4D 504C     DC.B      $80+$0E, 'COMPLETIONPROC', $00
  337.           4554 494F 4E50 
  338.           524F 4300      
  339. 0000003E: 0000           
  340.  
  341. Any help, flames, guidance etc greatly appreciated.
  342.  
  343. Thanks In Advance,
  344.  
  345. Chris B
  346. - ---------------------------------------------------------------------
  347. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  348. Internet: chris-b@cs.auckland.ac.nz
  349. Phone:    +64 9 373-7599 x6194
  350. Fax:      +64 9 373-7453                         Async, therefore I am.
  351. - ---------------------------------------------------------------------
  352.  
  353. +++++++++++++++++++++++++++
  354.  
  355. >From h+@nada.kth.se (Jon W{tte)
  356. Date: Fri, 19 Aug 1994 22:27:16 +0200
  357. Organization: Royal Institute of Something or other
  358.  
  359. In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  360. chris-b@cs.auckland.ac.nz (Chris Burns) wrote:
  361.  
  362. >version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  363. >68K version however, does not work. The _PBHGetVInfoAsync call returns all
  364. >kinds of bogus values instead of nice file manager errors.
  365.  
  366. That's because you're testing the return value of an asynchronous
  367. call. You're not supposed to do that, since there's no error to
  368. return there yet; instead you're supposed to test ioResult in the
  369. completion proc, or poll ioResult until it's not 1.
  370.  
  371. Cheers,
  372.  
  373.                 / h+
  374.  
  375.  
  376. --
  377.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  378.  
  379. "TextEdit does everything right."
  380.     ã Jon W{tte
  381.  
  382.  
  383. +++++++++++++++++++++++++++
  384.  
  385. >From chris-b@cs.auckland.ac.nz (Chris Burns)
  386. Date: Sun, 21 Aug 1994 18:19:12 +1200
  387. Organization: AucklandUniversity:ComputerScience:HMU
  388.  
  389. In article <9668AA7AE244.44E5E@klkmac004.nada.kth.se>, h+@nada.kth.se (Jon
  390. W{tte) wrote:
  391.  
  392. > In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  393. > chris-b@cs.auckland.ac.nz (Chris Burns) wrote:
  394. > >version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  395. > >68K version however, does not work. The _PBHGetVInfoAsync call returns all
  396. > >kinds of bogus values instead of nice file manager errors.
  397. > That's because you're testing the return value of an asynchronous
  398. > call. You're not supposed to do that, since there's no error to
  399. > return there yet; instead you're supposed to test ioResult in the
  400. > completion proc, or poll ioResult until it's not 1.
  401.  
  402. Sorry Jon, I don't buy it.
  403.  
  404. (I'm assuming that IM-IV Chpt 19 [File Manager] is still valid because it
  405. documents the low-level file manager routines; I havn't looked at
  406. NIM:Files)
  407.  
  408. Check out IM-IV Pg 119:
  409.  
  410. "Routines that are executed asynchronously return control to the calling
  411. program with the result code noErr as soon as the call is placed in the
  412. file I/O queue. This isn't an indication of successful call completion,
  413. but simply indicates that the call was successfully queued."
  414.  
  415. This is the case with nearly all async calls, they return a file manager
  416. error to the calling program (typically "noErr", but possibly "paramErr"
  417. or others), and then the real error somewhere in the param block (often
  418. also in D0) at completion proc time. These two errors should not be
  419. related in any way. The fact that D0 = $stuvwxyz upon exit of the
  420. completion proc should not mean that the calling code receives an error of
  421. $wxyz (D0.w).
  422.  
  423. IM-IV Pg 119:
  424.  
  425. "Warning: Completion routines are executed at interrupt level and must
  426. preserve all registers other than A0,A1, and D0-D2."
  427.  
  428. Surely this means my completion routine code can do what it wants with
  429. these regs without affecting anything.
  430.  
  431. IM-IV Pg 119:
  432.  
  433. "When your completion routine is called, register A0 points to the
  434. parameter block of the asynchronous call and register D0 contains the
  435. result code."
  436.  
  437. I read this to mean that these were "read-only" values (changes are not
  438. propagated back to calling code). I based this upon the fact that the
  439. completion proc may be called _well_ after the _PBHGetVInfo call. A remote
  440. file system such as an AppleShare volume will definitely be this way for
  441. mnay types of calls.
  442.  
  443.  
  444. I have kind-of solved this problem, but not to my satisfaction. If I save
  445. and restore the scratch regs (A0,A1, and D0-D2) the thing works properly.
  446. However, I don't think I should need to do this, and besides, its real
  447. ugly.
  448.  
  449. #if USES68KINLINES
  450. asm....
  451. #endif
  452.  
  453. yuck!
  454.  
  455. Any more ideas would be wonderful.
  456.  
  457. Thanks Heaps In Advance,
  458.  
  459. Chris B
  460. - ---------------------------------------------------------------------
  461. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  462. Internet: chris-b@cs.auckland.ac.nz
  463. Phone:    +64 9 373-7599 x6194
  464. Fax:      +64 9 373-7453                         Async, therefore I am.
  465. - ---------------------------------------------------------------------
  466.  
  467. +++++++++++++++++++++++++++
  468.  
  469. >From Jaeger@fquest.com (Brian Stern)
  470. Date: 21 Aug 1994 14:39:41 GMT
  471. Organization: The University of Texas at Austin, Austin, Texas
  472.  
  473. In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  474. chris-b@cs.auckland.ac.nz wrote:
  475.  
  476. > Hi All,
  477. > I've been looking into using async file manager calls, so I started
  478. > experimenting with an easy one, an indexed _PBHGetVInfoAsync call until
  479. > the error returned is nsvErr (no-such-volume: -35). This works perfectly
  480. > using sync calls. Things aren't so rosy on the async front tho'.
  481. > Being in a PowerPC friendly kind of mood (and running on a PM8100/80), I
  482. > thought "cool, I'll use UPPs for my completion routine specifiers, and
  483. > compile a fat app". This aspect is fine, and in fact, the PowerPC native
  484. > version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  485. > 68K version however, does not work. The _PBHGetVInfoAsync call returns all
  486. > kinds of bogus values instead of nice file manager errors.
  487. > Here's the entire code:
  488. > #if USES68KINLINES
  489. > #pragma parameter CompletionProc(__A0)
  490. > #endif
  491. > pascal void CompletionProc(HParmBlkPtr HPB)
  492. > {
  493. > long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  494. >     gNumDrivesDone++;
  495. >     DebugStr(((VolPBPtr)HPB)->VolName);
  496. >     SetA5(SavedA5);
  497. > }
  498. > Chris B
  499. > -----------------------------------------------------------------------
  500. > NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  501. > Internet: chris-b@cs.auckland.ac.nz
  502. > Phone:    +64 9 373-7599 x6194
  503. > Fax:      +64 9 373-7453                         Async, therefore I am.
  504. > -----------------------------------------------------------------------
  505.  
  506. So why not change it to this:
  507.  
  508. #if USES68KINLINES
  509. #pragma parameter __D0 CompletionProc(__A0)
  510. #endif
  511.  
  512. pascal OSErr CompletionProc(HParmBlkPtr HPB)
  513. {
  514. long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  515.  
  516.     gNumDrivesDone++;
  517.     DebugStr(((VolPBPtr)HPB)->VolName);
  518.  
  519.     SetA5(SavedA5);
  520.  
  521.     return HPB->ioResult;
  522.  
  523. }
  524.  
  525. No Assembly Required.
  526.  
  527. My reading of the passages in IM-IV that you quoted seems ambiguous about
  528. whether or not a completion routine returns a result in DO.  My first
  529. guess would have been no.
  530.  
  531. BTW, Use of the #pragma parameter in this way in MW works differently from
  532. Think C.  In Think you can only use #pragma parameter for inline calls. 
  533. This means that it's only useful for routines that you're calling, not for
  534. cases where your routines are called with parameters in registers.  So
  535. when compiling your CompletionProc with Think C, the compiler ignores the
  536. #pragma parameter and assumes that HPB was passed on the stack.  Oh well 
  537. :-(
  538.  
  539. -- 
  540. Brian  Stern  :-{)}
  541. Jaeger@fquest.com
  542.  
  543. +++++++++++++++++++++++++++
  544.  
  545. >From resnick@uiuc.edu (Pete Resnick)
  546. Date: Sun, 21 Aug 1994 13:02:57 -0500
  547. Organization: University of Illinois at Urbana-Champaign
  548.  
  549. In article <9668AA7AE244.44E5E@klkmac004.nada.kth.se>, h+@nada.kth.se (Jon
  550. W{tte) wrote:
  551.  
  552. >That's because you're testing the return value of an asynchronous
  553. >call. You're not supposed to do that, since there's no error to
  554. >return there yet; instead you're supposed to test ioResult in the
  555. >completion proc, or poll ioResult until it's not 1.
  556.  
  557. No, you're wrong. Inside Macintosh: Files, page 2-6 is quite explicit:
  558.  
  559.     Routines that are executed asynchronously return control to your
  560.     application with the result code noErr as soon as the call is placed in
  561.     the file I/O queue. Return of control does not signal successful
  562.     completion of the call, but simply successful queuing of the request.
  563.  
  564. You could plausibly get back an error if for some reason the Device
  565. Manager determined that the call could not be queued (a screwy refNum or
  566. the like). You are perfectly correct (though maybe using a little
  567. overkill) in checking the return code from an asynchronous routine. The
  568. problem lies somewhere else.
  569.  
  570. pr
  571. -- 
  572. Pete Resnick        (...so what is a mojo, and why would one be rising?)
  573. Doctoral Student - Philosophy Department, Gregory Hall, UIUC
  574. System manager - Cognitive Science Group, Beckman Institute, UIUC
  575. Internet: resnick@uiuc.edu
  576.  
  577. +++++++++++++++++++++++++++
  578.  
  579. >From benh@fdn.org (Benjamin Herrenschmidt)
  580. Date: Mon, 22 Aug 94 11:52:45 +0100
  581. Organization: (none)
  582.  
  583.  
  584.  
  585. >>That's because you're testing the return value of an asynchronous
  586. >>call. You're not supposed to do that, since there's no error to
  587. >>return there yet; instead you're supposed to test ioResult in the
  588. >>completion proc, or poll ioResult until it's not 1.
  589. >
  590. >No, you're wrong. Inside Macintosh: Files, page 2-6 is quite explicit:
  591. >
  592. >    Routines that are executed asynchronously return control to your
  593. >    application with the result code noErr as soon as the call is placed in
  594. >    the file I/O queue. Return of control does not signal successful
  595. >    completion of the call, but simply successful queuing of the request.
  596. >
  597. >You could plausibly get back an error if for some reason the Device
  598. >Manager determined that the call could not be queued (a screwy refNum or
  599. >the like). You are perfectly correct (though maybe using a little
  600. >overkill) in checking the return code from an asynchronous routine. The
  601. >problem lies somewhere else.
  602.  
  603. I remember something about async File Mgr. calls : unlike device manager
  604. calls, File Manager calls ALWAYS calls the completion routine to handle
  605. the result code, and the result of the async call itself MAY be garbage,
  606. event if something is wrong with the queue. The result code you should
  607. use is the one returned to the completion routine (or in the ioResult
  608. field of the paramblock)
  609.  
  610. I think i read this in a technote or a Q&A... 
  611.  
  612. BenH.
  613.  
  614. +++++++++++++++++++++++++++
  615.  
  616. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  617. Date: 23 Aug 94 18:05:13 +1200
  618. Organization: University of Waikato, Hamilton, New Zealand
  619.  
  620. In article <chris-b-2108941819120001@hmu7.cs.aukuni.ac.nz>, chris-b@cs.auckland.ac.nz (Chris Burns) writes:
  621. > In article <9668AA7AE244.44E5E@klkmac004.nada.kth.se>, h+@nada.kth.se (Jon
  622. > W{tte) wrote:
  623. >
  624. >> In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  625. >> chris-b@cs.auckland.ac.nz (Chris Burns) wrote:
  626. >>
  627. >> That's because you're testing the return value of an asynchronous
  628. >> call. You're not supposed to do that, since there's no error to
  629. >> return there yet; instead you're supposed to test ioResult in the
  630. >> completion proc, or poll ioResult until it's not 1.
  631. >
  632. > Sorry Jon, I don't buy it.
  633. >
  634. > (I'm assuming that IM-IV Chpt 19 [File Manager] is still valid because it
  635. > documents the low-level file manager routines; I havn't looked at
  636. > NIM:Files)
  637. >
  638. > Check out IM-IV Pg 119:
  639. >
  640. > "Routines that are executed asynchronously return control to the calling
  641. > program with the result code noErr as soon as the call is placed in the
  642. > file I/O queue. This isn't an indication of successful call completion,
  643. > but simply indicates that the call was successfully queued."
  644.  
  645. There is a technote somewhere which corrects this. Basically, you shouldn't
  646. bother checking the immediate return code from _any_ async call. I recently
  647. got burned with this doing async sound recording: my call to SPBRecord worked
  648. fine everywhere _except_ on a 500-series PowerBook, and then only when I
  649. invoked a combination of certain other recording options at the same time.
  650.  
  651. There is one situation where you should be careful about polling ioResult
  652. (And I'm not talking about being stupid, sitting in a tight loop at interrupt
  653. level, blocking the completion of the call you're polling for!): the PPC
  654. Toolbox. In System 7.0, the PPC Toolbox sets ioResult some time before it
  655. dequeues the parameter block from its request queue. This means if you have
  656. an interrupt routine that periodically checks the ioResult from a PPC Toolbox
  657. request, and assumes the parameter block can be reused the moment it goes 0
  658. or negative, you could be in for a crash. If you specify a completion routine,
  659. then the parameter block can be safely reused when this routine is called.
  660.  
  661. I understand this might be fixed in later Systems, but I'm not sure which ones.
  662. If Jim Luther is reading this, he might be able to update us...
  663.  
  664. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  665. Info & Tech Services Division              fax: +64-7-838-4066
  666. University of Waikato            electric mail: ldo@waikato.ac.nz
  667. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  668.  
  669. +++++++++++++++++++++++++++
  670.  
  671. >From chris-b@cs.auckland.ac.nz (Chris Burns)
  672. Date: Wed, 24 Aug 1994 12:47:36 +1200
  673. Organization: AucklandUniversity:ComputerScience:HMU
  674.  
  675. In article <Jaeger-2108940941410001@slip-1-88.ots.utexas.edu>,
  676. Jaeger@fquest.com (Brian Stern) wrote:
  677.  
  678. > So why not change it to this:
  679. > #if USES68KINLINES
  680. > #pragma parameter __D0 CompletionProc(__A0)
  681. > #endif
  682. > pascal OSErr CompletionProc(HParmBlkPtr HPB)
  683. > {
  684. > long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  685. >     gNumDrivesDone++;
  686. >     DebugStr(((VolPBPtr)HPB)->VolName);
  687. >     SetA5(SavedA5);
  688. >     return HPB->ioResult;
  689. > }
  690. > No Assembly Required.
  691.  
  692. Yeah, good idea Brian. This actually works on both platforms and does not
  693. use any asm. Thanks for the idea, I'll end up using this.
  694.  
  695. It should not be required tho'. Apple docs clearly state that D0 doesn't
  696. have to be save/restored and don't say the error should be returned in D0
  697. either (in fact this cannot be the case because the completion proc could
  698. potentially execute _well after_ the original error has been returned.
  699. Maybe this call cannot be done truely async?
  700.  
  701. Thanks Again,
  702.  
  703. Chris B
  704. - ---------------------------------------------------------------------
  705. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  706. Internet: chris-b@cs.auckland.ac.nz
  707. Phone:    +64 9 373-7599 x6194
  708. Fax:      +64 9 373-7453                         Async, therefore I am.
  709. - ---------------------------------------------------------------------
  710.  
  711. +++++++++++++++++++++++++++
  712.  
  713. >From Clinton Bauder <gecko1@applelink.apple.com>
  714. Date: Wed, 24 Aug 1994 21:02:10 GMT
  715. Organization: Apple Computer Inc.
  716.  
  717. In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz> Chris Burns,
  718. chris-b@cs.auckland.ac.nz writes:
  719. >
  720. >        Err = PBHGetVInfoAsync((HParmBlkPtr)VPB);
  721. >
  722. >        switch (Err)
  723. >        {
  724. >            case noErr:
  725. >                break;
  726. >
  727. >            case nsvErr:
  728. >                continue;
  729. >
  730. >            default:
  731. >                DebugStr("\p_PBHGetVInfoAsync FAILED");
  732. >                break;
  733. >        }
  734.  
  735. If you are making an async call you have to wait for it to complete.  A
  736. return of noErr from an async call doesn't mean it is done.  I merely
  737. means the PB was correctly filled out and has been accepted (queued) by
  738. the File Mananger.  At some later point it will be completed and the
  739. ioResult field will be updated with the correct result and the completion
  740. routine called.  Your application needs to either poll ioResult (wait til
  741. it is not 1 - which means in progress) or poll some other variable which
  742. is set by the completion routine.  To really take advantage of async IO
  743. you should try and do something with the time in between when you make
  744. the file system call and when ioResult changes to <= noErr.
  745.  
  746. Clinton
  747. - -------------------------------------------------------------
  748. Clinton Bauder        | Opinions expressed are very likely to
  749. SCSI Grunt and Chief  | be entirely different from the official
  750. Herpetoculturist      | party line of Apple Computer Inc.
  751. Apple Computer Inc.   | Support your local herp society.
  752. - -------------------------------------------------------------
  753.  
  754. +++++++++++++++++++++++++++
  755.  
  756. >From jumplong@aol.com (Jump Long)
  757. Date: 26 Aug 1994 01:42:07 -0400
  758. Organization: America Online, Inc. (1-800-827-6364)
  759.  
  760. In article <chris-b-2108941819120001@hmu7.cs.aukuni.ac.nz>,
  761. chris-b@cs.auckland.ac.nz (Chris Burns) writes:
  762.  
  763. >Any more ideas would be wonderful.
  764.  
  765. I responded to Chris via email with this:
  766.  
  767. - ---
  768.  
  769. Chris,
  770.  
  771. You need to get a copy of develop magazine issue #13 and read the article
  772. I wrote called "Asynchronous Routines on the Macintosh".  It answers many
  773. of your current questions and will answer many of the questions you're
  774. going to have in the future :-)  In many cases while writing that article,
  775. I found that Inside Mac was either wrong, or just didn't describe things
  776. completely.
  777.  
  778. Here's some specific information for what you observed.
  779.  
  780. 1) If the File Manager isn't busy when it receives a request (asynchronous
  781. or synchronous), it doesn't queue it - it begins execution of the request
  782. immediately. If the File Manager is busy handling another request, *then*
  783. the request is queued until the all requests before it in the queue have
  784. executed. If the request is a synchronous request, then the system spins
  785. in SyncWait waiting for the synchronous request to be executed. If the
  786. request is an asynchronous request and it is queued, then control is
  787. returned to the caller after the request is queued
  788.  
  789. 2) When the current request is finished executing and the File Manager has
  790. called its completion routine, the File Manager begins excution of the
  791. next request in the queue (if any).
  792.  
  793. 3) Once the File Manager starts executing an asynchronous request, it
  794. doesn't give up control until it is either: a) done handling the request
  795. or b) makes an asynchronous request to a device driver to read or write
  796. block(s) of data and the device driver returns control to the File Manager
  797. while it handles the request asynchronously. The part "while it handles
  798. the request asynchronously" is important because if the driver handles all
  799. requests synchronously (like the old SCSI Manager does), then the File
  800. Manager doesn't get control back from the driver call until it has
  801. completed, and in that case, the File Manager continues with the execution
  802. of the request.
  803.  
  804. So, when you call PBHGetVInfoAsync, if the File Manager isn't busy, it
  805. starts execution of the request immediately.  Since GetVInfo requests
  806. don't cause calls to the driver (unless you pass a working directory
  807. number instead of real volume reference number), there is nothing to stop
  808. the File Manager from completing the request. That's why you're seeing the
  809. request complete immediately.
  810.  
  811. The reason you're seeing the 5 you slam into DO in the completion routine
  812. is that the File Manager uses D0 to return function results to
  813. *synchronous* requests.  With an asynchronous request, you never know what
  814. the real result of the request is until it completes, so the File Manager
  815. sets D0 to 0 when it *starts* execution of the request and doesn't worry
  816. about returning the ioResult value (which is 1 while the call is queued or
  817. executing) to the caller. Here's how we (Apple) recommend making
  818. asychronous File Manager requests (note: Device Manager calls are handled
  819. differently - read the article):
  820.  
  821. /* Make an asynchronous request. */
  822. /* Ignore the function result and look for the */
  823. /* real result when the call completes. */
  824. (void) PBHGetVInfoAsync(&pb);
  825.  
  826. or in Pascal:
  827.  
  828. if (PBHGetVInfoAsync(@pb) <> noErr)
  829.   ; { do nothing, check result at completion }
  830.  
  831. - ---
  832.  
  833. - Jim Luther
  834.  
  835.  
  836. ---------------------------
  837.  
  838. >From bentley@MCS.COM (Mike Bentley)
  839. Subject: Future of ASLM
  840. Date: 13 Aug 1994 17:46:25 -0500
  841. Organization: MCSNet Subscriber Account, Chicago's First Public-Access Internet!
  842.  
  843. What I meant to ask was,
  844. after finally getting something like a shared library manager out for the 680x0
  845. machines, how does ASLM fit into the plan when building a shared library file
  846. with both 680x0 and PowerPC code in it?
  847.  
  848. My guess is that this doesn't happen, that an ASLM library gets a file and the
  849. equivalent code fragment import library (a 'shlb' -- too bad, 'shlp' is funnier)
  850. is a separate file. This probably means that there is some differences in
  851. implementation detail in the source code.
  852.  
  853. -Mike Bentley
  854. Crenelle Inc.
  855.  
  856.  
  857. +++++++++++++++++++++++++++
  858.  
  859. >From garryh@seeding.apple.com (Garry Hornbuckle)
  860. Date: 26 Aug 1994 18:39:45 GMT
  861. Organization: Apple Computer, Inc.
  862.  
  863. In article <32jig1$42k@Mercury.mcs.com>, bentley@MCS.COM (Mike Bentley) wrote:
  864.  
  865. > What I meant to ask was,
  866. > after finally getting something like a shared library manager out for
  867. the 680x0
  868. > machines, how does ASLM fit into the plan when building a shared library file
  869. > with both 680x0 and PowerPC code in it?
  870.  
  871. ==========================================
  872. Macintosh Dynamic Linked Libraries (DLLs)
  873. ==========================================
  874.  
  875. Apple has developed a complete technology solution for shared code, shared
  876. objects, and dynamic linked libraries (DLLs) on the Macintosh. Parts of
  877. this solution are available today, with additional parts becoming
  878. available in the coming months.
  879.  
  880. There are three key components to Macintosh DLL strategy:
  881. ĆApple's Shared Library Manager (ASLM),
  882. ĆApple's Code Fragment Manager (CFM), and
  883. ĆIBM's System Object Model (SOM).
  884.  
  885. Here is a brief summary of ASLM, CFM, and SOM ...
  886.  
  887. ASLM
  888. - ----------
  889. Apple Shared Library Manager is the first component of Apple's DLL
  890. solution to be available, and is an integral part of our overall DLL
  891. offering.  ASLM supports shared code libraries for both procedural and
  892. object oriented development efforts. A number of Apple products have
  893. already been based on ASLM, including MacSNMP and the GeoPort
  894. communications pod technology. Third parties such as Microsoft (OLE for
  895. Macintosh), Novell (AppWare), and Aldus have also adopted ASLM to support
  896. their DLL needs.
  897.  
  898. In the future, additonal functionality will be added to the Macintosh
  899. operating system as ASLM libraries, including our next generation
  900. networking, the Open Transport Communications Architecture.
  901.  
  902. ASLM v1.1.2 is the currently shipping release. ASLM v2.0 is under
  903. development, to provide support for native code shared libraries on Power
  904. Macintosh. ASLM 2.x sits on top of (is based on) the Code Fragment
  905. Manager. This work is expected to produce final product in 4Q CY94.
  906.  
  907. As CFM becomes available on 68K Macintosh (see below), a future ASLM
  908. version (2.1) will support CFM on 68K as well, while continuing to support
  909. current 68K-style shared libraries. Thus,  ASLM v2.x will provide
  910. compatibility for ASLM v1.1, v1.1.1, and v1.1.2 applications.
  911.  
  912. ASLM adds higher-level object-oriented capabilities to the environment
  913. that are not a part of the Code Fragment Manager itself. ASLM is the
  914. technology of choice when you:
  915.  
  916. Ä  need DLLs on 68K today ... ASLM is shipping
  917. Ä  want simplicity and elegance with C++
  918. Ä  want a simple but powerful extension mechanism using C, Pascal, or ASM
  919. Ä  have performance sensitive (i.e., interrupt time) needs like networking
  920. Ä  want run-time transparent dynamic loading and unloading of code
  921. Ä  DON'T need transparent access to per-context global data
  922. Ä  DON'T need to solve the "fragile base class" problem for C++
  923.  
  924. CFM
  925. - ----------
  926. As a second key step in our DLL strategy, Apple has developed a new
  927. foundation layer for dynamic linking on the Macintosh known as the Code
  928. Fragment Manager (CFM). CFM will be a core part of System Software on the
  929. PowerPC Macintosh.
  930.  
  931. CFM is also being developed for the Macintosh on 68K. This work is
  932. expected to produce final product in 1Q CY95.
  933.  
  934. The Code Fragment Manager provides code sharing and dynamic linking, with
  935. features supporting per-context globals. CFM will be fully supported by
  936. development tools on Macintosh.
  937.  
  938. CFM is the best bet when your application:
  939. Ä  runs on PowerPC Macintosh first, and 68K Macintosh later
  940. Ä  needs only basic dynamic loading and unloading of shared code
  941. Ä  needs to reduce system overhead to the minimum amount
  942. Ä  needs transparent access to per-context global data
  943. Ä  DOES NOT need system-level OOP support
  944.  
  945.  
  946. SOM
  947. - ----------
  948. Apple is in the process of licensing and porting IBM's System's Object
  949. Model (SOM) technology to Macintosh. SOM is a multi-platform standard
  950. providing for system-level sharable objects in a language-neutral way. SOM
  951. also solves the "fragile base class" problem, avoiding the need for client
  952. libraries to be recompiled when the base class they inherit from is in a
  953. different library and is changed.
  954.  
  955. To offer these benefits (multi-platform support and fragile base-class
  956. resolution) SOM requires the use of an IDL as a first step in the
  957. development process.
  958.  
  959. SOM runs on top of CFM, and thus will become available on both 68K and
  960. PowerPC Macintosh.
  961.  
  962. SOM is a foundation technology for OpenDoc. 
  963.  
  964.  
  965. Integration
  966. - ----------
  967. SOM and ASLM will both live in a CFM run-time environment, and will both
  968. be available on both 68K and PowerPC Macintosh. Thus there will be no
  969. impediment to co-existence of ASLM and SOM, or to applications that use
  970. both ASLM and SOM. In fact, a SOM class could easily call an ASLM class or
  971. vice-versa.
  972.  
  973. Over time, some of the functionality provided by ASLM may be supplanted by
  974. SOM. However, ASLM APIs will be preserved. As a result, applications
  975. written to the ASLM API may have some functionality transparently migrated
  976. to SOM in the future.
  977.  
  978. - -----------------------------------------------------------------
  979. Garry Hornbuckle    Product Manager, Communications & Collaboration
  980. - -----------------------------------------------------------------
  981. "If I told you that I   | email      garryh@seeding.apple.com
  982.  spoke only for myself  | applelink  HORNBUCKLE1
  983.  would you believe me?" | fax        (408) 974-1211
  984. - -----------------------------------------------------------------
  985.  
  986. ---------------------------
  987.  
  988. >From Jaeger@fquest.com (Brian Stern)
  989. Subject: Review of PowerMac devtools available
  990. Date: 26 Aug 1994 03:20:05 GMT
  991. Organization: The University of Texas at Austin, Austin, Texas
  992.  
  993. If you haven't come across it yet, there is an interesting article titled: 
  994.  
  995. PUTTING THE C(++) INTO POWER MACINTOSH by Jon Lansdell (August 19th 1994),
  996.  
  997. that has appeared in the current version of powerPC news.  It is the first
  998. part of a two part series that will review the four native development
  999. environments for the PowerMac.  In case you're wondering these are:
  1000.  
  1001. *Symantec's Cross Development kit*
  1002. *MPW*
  1003. *The Absoft C/C++ SDK* 
  1004. *CodeWarrior *
  1005.  
  1006. Here are a few quotes taken completely out of context:
  1007.  
  1008. Symantec's image amongst the Macintosh developer community was somewhat
  1009. tarnished by release 6.0 of Symantec C++ for the Macintosh and reports
  1010. that it was somewhat buggy. 
  1011.  
  1012. MPW - tried, tested and old.  ETO#15 and the MPW Pro CD both contain
  1013. pre-release native versions of the MPW Shell and various tools, including
  1014. PPCC. While this does compile applications around twice as fast, the
  1015. Linker still has to run under emulation, so while Apple work on a new
  1016. native development environment, developers have plenty of time for coffee
  1017. breaks during the build process. 
  1018.  
  1019. The Absoft SDK includes a couple of extras which give it claim to be a
  1020. fully rounded development environment.  Although the Linker and Compiler
  1021. are native, it does cry out to be part of a completely native development
  1022. environment.
  1023.  
  1024. You can find the article via your favorite web-client at:
  1025.  
  1026. http://power.globalnews.com:8000/
  1027.  
  1028. -- 
  1029. Brian  Stern  :-{)}
  1030. Jaeger@fquest.com
  1031.  
  1032. ---------------------------
  1033.  
  1034. >From scotth@jaguar.visix.com (Scott Hofmann)
  1035. Subject: SetDialogDefaultItem() not doing anything!
  1036. Date: Thu, 25 Aug 1994 13:42:32 GMT
  1037. Organization: Visix Software, Reston, Virginia
  1038.  
  1039. In some code I've written for a preferences dialog, I use the calls
  1040. SetDialogDefaultItem() and SetDialogCancelItem() to make my "OK" and "Cancel"
  1041. buttons look and perform according to Apple spec, but both traps aren't doing
  1042. anything- it's like they exist, but are bound to no-op. This happens both in
  1043. Symantec C++ 6.0, using the glue from the THINK Ref 2.0, and in Metrowerks CW4.
  1044. I'm working on a Centris 650 running System 7.1, so I'm pretty sure my ROMs
  1045. contain that trap - could I be mistaken about this? Has anyone use gotten these
  1046. traps to work? Thanks,
  1047.  
  1048.                                                             scott
  1049. -- 
  1050. - -----------------------------------------------------------------------------
  1051. J. Scott Hofmann                        | "You've saved humanity...once again"
  1052. scotth@visix.com                        |       -Q to Capt. Picard, ST:TNG
  1053.  
  1054. +++++++++++++++++++++++++++
  1055.  
  1056. >From hanrek@cts.com (Mark Hanrek)
  1057. Date: 25 Aug 1994 20:18:00 GMT
  1058. Organization: The Information Workshop
  1059.  
  1060. In article <SCOTTH.94Aug25094232@jaguar.visix.com>,
  1061. scotth@jaguar.visix.com (Scott Hofmann) wrote:
  1062.  
  1063. > In some code I've written for a preferences dialog, I use the calls
  1064. > SetDialogDefaultItem() and SetDialogCancelItem() to make my "OK" and "Cancel"
  1065. > buttons look and perform according to Apple spec, but both traps aren't doing
  1066. > anything- it's like they exist, but are bound to no-op. This happens both in
  1067. > Symantec C++ 6.0, using the glue from the THINK Ref 2.0, and in
  1068. Metrowerks CW4.
  1069. > I'm working on a Centris 650 running System 7.1, so I'm pretty sure my ROMs
  1070. > contain that trap - could I be mistaken about this? Has anyone use
  1071. gotten these
  1072. > traps to work? Thanks,
  1073.  
  1074.  
  1075. There is a certain "time" that these calls should be made so that they are
  1076. associated with the current dialog. Otherwise, it could cause problems in
  1077. the cases in which you don't want the system to do its thing for you.  
  1078.  
  1079. In other words, the effect is not global, but rather "contextual". 
  1080. Example source code will show you what you need to know.
  1081.  
  1082. Hope this helps.
  1083.  
  1084. Mark Hanrek
  1085.  
  1086. +++++++++++++++++++++++++++
  1087.  
  1088. >From dirk@gaga.maschinenbau.uni-dortmund.de (Dirk Froehling)
  1089. Date: Fri, 26 Aug 1994 09:41:03 +0100
  1090. Organization: UniDO
  1091.  
  1092. In article <hanrek-2508941320100001@auke.cts.com>, hanrek@cts.com (Mark
  1093. Hanrek) wrote:
  1094.  
  1095. > In article <SCOTTH.94Aug25094232@jaguar.visix.com>,
  1096. > scotth@jaguar.visix.com (Scott Hofmann) wrote:
  1097. > > In some code I've written for a preferences dialog, I use the calls
  1098. > > SetDialogDefaultItem() and SetDialogCancelItem() to make my "OK" and 
  1099. > There is a certain "time" that these calls should be made so that they are
  1100. > associated with the current dialog.
  1101.  
  1102. Try something like (this is Pascal, but...):
  1103.  
  1104.         myDlog := GetNewDialog(myID, nil, pointer(-1));
  1105.  
  1106.         myErr := SetDialogDefaultItem(myDlog, OK);
  1107.         myErr := SetDialogCancelItem(myDlog, cancel);
  1108.  
  1109.      { here it comes: }
  1110.         myErr := GetStdFilterProc(filterIt); { don't use your own filter }
  1111.  
  1112.         repeat
  1113.             ModalDialog(filterIt, itemHit);
  1114.             { do something }
  1115.         until itemHit in [OK, Cancel];
  1116.  
  1117. -- 
  1118. | Dirk Froehling - Germany, Uni Dortmund, FB Maschinenbau, LS Mechanik |
  1119. | dirk@gaga.maschinenbau.uni-dortmund.de            GEnie: D.FROEHLING |
  1120.  
  1121. +++++++++++++++++++++++++++
  1122.  
  1123. >From gbolsinga@aol.com (GBolsinga)
  1124. Date: 26 Aug 1994 16:02:07 -0400
  1125. Organization: America Online, Inc. (1-800-827-6364)
  1126.  
  1127. In article <dirk-260894094103@129.217.230.3>,
  1128. dirk@gaga.maschinenbau.uni-dortmund.de (Dirk Froehling) writes:
  1129.  
  1130. >Try something like (this is Pascal, but...):
  1131. >
  1132. >  myDlog := GetNewDialog(myID, nil, pointer(-1));
  1133. >
  1134. >  myErr := SetDialogDefaultItem(myDlog, OK);
  1135. >  myErr := SetDialogCancelItem(myDlog, cancel);
  1136. >
  1137. >  { here it comes: }
  1138. >  myErr := GetStdFilterProc(filterIt); { don't use your own filter }
  1139. >
  1140. >  repeat
  1141. >   ModalDialog(filterIt, itemHit);
  1142. >   { do something }
  1143. >  until itemHit in [OK, Cancel];
  1144.  
  1145. You could use your own filter which pre-filters the call and then calls
  1146. the 
  1147. standard filter proc
  1148.  
  1149. Greg
  1150. MPI Multimedia
  1151. /* These are MY opinions */
  1152.  
  1153.  
  1154. +++++++++++++++++++++++++++
  1155.  
  1156. >From stk@uropax.contrib.de (Stefan Kurth)
  1157. Date: 27 Aug 1994 18:20:16 +0200
  1158. Organization: Contributed Software GbR
  1159.  
  1160. In article <33lhnv$m7r@search01.news.aol.com>,
  1161. GBolsinga <gbolsinga@aol.com> wrote:
  1162.  
  1163. > In article <dirk-260894094103@129.217.230.3>,
  1164. > dirk@gaga.maschinenbau.uni-dortmund.de (Dirk Froehling) writes:
  1165. >
  1166. > > { don't use your own filter }
  1167. >
  1168. > You could use your own filter which pre-filters the call and then calls
  1169. > the standard filter proc
  1170.  
  1171. Yes, but remember to call it like this:
  1172.  
  1173.     GetStdFilterProc(&theFilterProc);
  1174.  
  1175.     asm {
  1176.         move.l d3, -(a7)
  1177.     }
  1178.  
  1179.     result = theFilterProc(theDialog, &theEvent, &itemHit);
  1180.  
  1181.     asm {
  1182.         move.l (a7)+, d3
  1183.     }
  1184.  
  1185.     return result;
  1186.  
  1187. since the std filter proc trashes d3, which can cause strange things to
  1188. happen to your local variables.
  1189.  
  1190. ________________________________________________________________________
  1191. Stefan Kurth                 Berlin, Germany              stk@contrib.de
  1192.  
  1193. ---------------------------
  1194.  
  1195. >From woody@alumni.caltech.edu (William Edward Woody)
  1196. Subject: Trouble making floating windows work with modeless dialogs
  1197. Date: 26 Aug 1994 06:56:43 GMT
  1198. Organization: California Institute of Technology, Alumni Association
  1199.  
  1200.  
  1201. I'm having a problem making modeless dialogs work with floating windows.
  1202. The problem is with 'IsDialogEvent()' and 'DialogSelect()'.
  1203.  
  1204. When I receive the event from WaitNextEvent(), I first determine if the
  1205. event is for a modal dialog through 'IsDialogEvent()', and if it is,
  1206. I call my subroutine which gets the calls 'DialogSelect()' to process
  1207. the event, and then handle the control ID if DialogSelect returns TRUE.
  1208.  
  1209. The problem is that it seems that the modeless dialog is not being
  1210. processed correctly if there is a floating window up. I think what's
  1211. going on is that as the floating window is the frontmost window in the
  1212. WindowList, IsDialogEvent() and DialogSelect() do not handle mouseDown,
  1213. nullEvent, or keyDown events at all.
  1214.  
  1215. Kludging the system to put the dialog at the head of the WindowList
  1216. global for processing of the IsDialogEvent() and DialogSelect() routines
  1217. allows me to click on buttons, but edit fields are handled completely
  1218. wrong.
  1219.  
  1220. What I want to know is, what can I do to make IsDialogEvent() and
  1221. DialogSelect() work. (I don't want to use the GhostWindow global because
  1222. I may have more than one floating window up at once.) If I can't
  1223. make those routines work, then how can I replace the routines with
  1224. code of my own to handle dialog events?
  1225.  
  1226. I'm really stuck here, and I don't know where to turn. This is my last
  1227. hope.
  1228.  
  1229. advTHANKSance.
  1230.  
  1231.                         - Bill
  1232. -- 
  1233. o William Edward Woody      | "I'm shying from the light
  1234.   In Phase Consulting      |  I always loved the night
  1235.   337 West California #4  |  And now you offer me eternal darkness"
  1236.   Glendale, CA 91203      |          - Depeche Mode, "One Caress"
  1237.  
  1238. +++++++++++++++++++++++++++
  1239.  
  1240. >From woody@alumni.caltech.edu (William Edward Woody)
  1241. Date: 26 Aug 1994 22:19:16 GMT
  1242. Organization: California Institute of Technology, Alumni Association
  1243.  
  1244. a while ago (yesterday?) I wrote:
  1245. > I'm having a problem making modeless dialogs work with floating windows.
  1246. > The problem is with 'IsDialogEvent()' and 'DialogSelect()'.
  1247. > What I want to know is, what can I do to make IsDialogEvent() and
  1248. > DialogSelect() work. (I don't want to use the GhostWindow global because
  1249. > I may have more than one floating window up at once.) If I can't
  1250. > make those routines work, then how can I replace the routines with
  1251. > code of my own to handle dialog events?
  1252.  
  1253. Well, without a solution I could use fast enough, I bit the bullet and wrote
  1254. the routines MIsDialogEvent() and MDialogSelect() to replace IsDialogEvent()
  1255. and DialogSelect() to solve my problem.
  1256.  
  1257. I have attached the code I wrote below, so others can also do modeless
  1258. dialogs and floating windows at the same time.
  1259.  
  1260. NOTE:    In these routines below, MFrontWindow() is the replacement to
  1261.     FrontWindow() which figures out the frontmost non-floater window.
  1262.  
  1263. NOTE:    These routines are not well-tested. They work for me, but they
  1264.     may have bugs (some severe) which prevent their adequate use.
  1265.     Note that they were written to be used together, and are not
  1266.     compatable with their 'IsDialogEvent()/DialogSelect()' counterparts.
  1267.     I don't know why this is; it just is.
  1268.  
  1269. Code follows:
  1270.  
  1271. - -CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---
  1272.  
  1273. /*  MIsDialogEvent
  1274.  *
  1275.  *    Is this an event for this dialog box?
  1276.  */
  1277.  
  1278. Boolean MIsDialogEvent(EventRecord *event)
  1279. {
  1280.     WindowPtr w;
  1281.     short where;
  1282.     
  1283.     switch (event->what) {
  1284.     case mouseDown:
  1285.         where = FindWindow(event->where,&w);
  1286.         if (where != inContent) w = NULL;
  1287.         else if (w != MFrontWindow()) w = NULL;
  1288.         break;
  1289.     case updateEvt:
  1290.     case activateEvt:
  1291.         w = (WindowPtr)(event->message);
  1292.         break;
  1293.     case keyDown:
  1294.     case autoKey:
  1295.     default:
  1296.         w = MFrontWindow();
  1297.         break;
  1298.     }
  1299.     if (w == NULL) return 0;
  1300.     if (((WindowPeek)w)->windowKind == dialogKind) return 1;
  1301.     return 0;
  1302. }
  1303.  
  1304. /*  MDialogSelect
  1305.  *
  1306.  *    Do the dialog select routines. This does all of the dialog
  1307.  *  processing stuff for this dialog window if it is one.
  1308.  */
  1309.  
  1310. Boolean MDialogSelect(EventRecord *event, DialogPtr *dlog, short *item)
  1311. {
  1312.     WindowPtr w;
  1313.     DialogPeek peek;
  1314.     short where;
  1315.     Handle h;
  1316.     Rect r;
  1317.     TEHandle text;
  1318.     char c;
  1319.     short index;
  1320.     short length;
  1321.     Point pt;
  1322.     long tmp;
  1323.     
  1324.     /*
  1325.      *  Determine the dialog window that is being used here.
  1326.      */
  1327.     
  1328.     switch (event->what) {
  1329.         case mouseDown:
  1330.         case mouseUp:
  1331.             where = FindWindow(event->where,&w);
  1332.             if (where != inContent) w = NULL;
  1333.             break;
  1334.         case updateEvt:
  1335.         case activateEvt:
  1336.             w = (WindowPtr)(event->message);
  1337.             break;
  1338.         default:
  1339.             w = MFrontWindow();
  1340.             break;
  1341.     }
  1342.     if (w == NULL) return 1;        // Not my event...
  1343.     if (((WindowPeek)w)->windowKind != dialogKind) return 1;
  1344.     
  1345.     /*
  1346.      *  Now, actually do this event as appropriate
  1347.      */
  1348.     
  1349.     *dlog = w;                // The dialog I was handling.
  1350.     *item = 0;                // Default item (0)
  1351.     peek = (DialogPeek)w;        // So I can get at internal stuff
  1352.     switch (event->what) {
  1353.     
  1354.         /*
  1355.          *  Activate/Deactivate
  1356.          *
  1357.          *    This activates or deactivates the text edit field
  1358.          *  if it is present in the dialog box.
  1359.          */
  1360.         
  1361.         case activateEvt:
  1362.             SetPort(w);
  1363.             text = peek->textH;
  1364.             if (text) {
  1365.                 if (event->modifiers & activeFlag) {
  1366.                     TEActivate(text);
  1367.                 } else {
  1368.                     TEDeactivate(text);
  1369.                 }
  1370.             }
  1371.             return 0;            // Further processing not needed
  1372.         
  1373.         /*
  1374.          *  Update
  1375.          *
  1376.          *    This simply draws the contents of this thing
  1377.          */
  1378.         
  1379.         case updateEvt:
  1380.             SetPort(w);
  1381.             BeginUpdate(w);
  1382.             UpdateDialog(w,w->visRgn);
  1383.             EndUpdate(w);
  1384.             return 0;            // Further processing not needed
  1385.         
  1386.         /*
  1387.          *  Null event processing
  1388.          *
  1389.          *    Blink the cursor
  1390.          */
  1391.         
  1392.         default:
  1393.         case nullEvent:
  1394.             SetPort(w);
  1395.             if (peek->textH) TEIdle(peek->textH);
  1396.             return 0;            // Further processing not needed
  1397.         
  1398.         /*
  1399.          *  Key events
  1400.          *
  1401.          *    This handles keyboard events by processing the enter/
  1402.          *  escape keys as buttons 1 and 2; otherwise, pass to the
  1403.          *  current edit box, if any.
  1404.          */
  1405.         
  1406.         case keyDown:
  1407.         case autoKey:
  1408.             SetPort(w);
  1409.             c = (unsigned char)(event->message & charCodeMask);
  1410.             
  1411.             /*
  1412.              *  Enter, escape processing
  1413.              */
  1414.             
  1415.             if ((c == 0x03) || (c == 0x0D) || (c == 0x1B)) {                
  1416.                 if ((c == 0x03) || (c == 0x0D)) {
  1417.                     *item = 1;
  1418.                 } else {
  1419.                     *item = 2;
  1420.                 }
  1421.                 
  1422.                 GetDialogItem(w,*item,&where,&h,&r);
  1423.                 HiliteControl((ControlHandle)h,inButton);
  1424.                 Delay(5,&tmp);
  1425.                 HiliteControl((ControlHandle)h,0);
  1426.                 return 1;        // Further processing needed
  1427.             }
  1428.             
  1429.             /*
  1430.              *  Tab processing
  1431.              */
  1432.             
  1433.             if (c == 0x09) {        // Horizontal tab key
  1434.                 if (peek->textH == NULL) return 0;    // Can't deal with it.
  1435.                 length = *((short *)(*(peek->items))) + 1;
  1436.                 index = peek->editField+2;        // Skip this one
  1437.                 
  1438.                 /*
  1439.                  *  Find the next edit item and select it
  1440.                  */
  1441.                 
  1442.                 while (index <= length) {
  1443.                     GetDialogItem(w,index,&where,&h,&r);
  1444.                     if ((0x7F & where) == 16) {        // This is an edit item
  1445.                         SelIText(w,index,0,32767);    // Move edit, select me
  1446.                         *item = index;
  1447.                         return ((where & 0x80) == 0) ? 1 : 0;
  1448.                     }
  1449.                     index++;
  1450.                 }
  1451.                 index = 1;                // Wrap to beginning
  1452.                 while (index <= length) {
  1453.                     GetDialogItem(w,index,&where,&h,&r);
  1454.                     if ((0x7F & where) == 16) {        // This is an edit item
  1455.                         SelIText(w,index,0,32767);    // Move edit, select me
  1456.                         *item = index;
  1457.                         return ((where & 0x80) == 0) ? 1 : 0;
  1458.                     }
  1459.                     index++;
  1460.                 }
  1461.                 *item = 0;
  1462.                 return 0;                // Huh? Dunno...
  1463.             }
  1464.             
  1465.             /*
  1466.              *  Normal keyboard processing
  1467.              */
  1468.             
  1469.             text = peek->textH;
  1470.             if (text == NULL) return 0;            // No edit item to do
  1471.             
  1472.             *item = peek->editField+1;            // Item ID we're doing
  1473.             TEKey(c,text);                // Do character process
  1474.             
  1475.             GetDialogItem(w,*item,&where,&h,&r);    // Return appropriate
  1476.             return ((where & 0x80) == 0) ? 1 : 0;    // for enable flag
  1477.         
  1478.         /*
  1479.          *  Mouse down:
  1480.          *
  1481.          *    track the controls or the edit fields as appropriate
  1482.          */
  1483.         
  1484.         case mouseDown:
  1485.             SetPort(w);
  1486.             pt = event->where;
  1487.             GlobalToLocal(&pt);
  1488.             
  1489.             /*
  1490.              *  Determine where the mouse went down
  1491.              */
  1492.             
  1493.             index = FindDItem(w,pt)+1;
  1494.             if (index == 0) return 0;        // Not on anything
  1495.             GetDialogItem(w,index,&where,&h,&r);
  1496.             *item = index;
  1497.             
  1498.             /*
  1499.              *  Handle inactive objects
  1500.              */
  1501.             
  1502.             if (where & 0x80) {
  1503.                 if (where == 0x90) {        // Edit item here.
  1504.                 
  1505.                     /*
  1506.                      *  Handle edit selection even if inactive
  1507.                      */
  1508.                     
  1509.                     if (peek->editField + 1 != index) {
  1510.                         SelIText(w,index,0,32767);
  1511.                     }
  1512.                     TEClick(pt,(event->modifiers & shiftKey) ? 1 : 
  1513. 0,peek->textH);
  1514.                 }
  1515.                 return 0;
  1516.             }
  1517.             
  1518.             /*
  1519.              *  Process according to where I'm at
  1520.              */
  1521.             
  1522.             switch (where) {
  1523.                 default:
  1524.                     return 1;            // Just return the ID.
  1525.                 case 4:
  1526.                 case 5:
  1527.                 case 6:
  1528.                 case 7:
  1529.                     /*
  1530.                      *  Click on a standard control object
  1531.                      */
  1532.                     
  1533.                     if (TrackControl((ControlHandle)h,pt,NULL)) return 1; // do 
  1534. it.
  1535.                     return 0;            // don't do it.
  1536.                 case 16:            // Handle edit box
  1537.                     if (peek->editField + 1 != index) {
  1538.                         SelIText(w,index,0,32767);
  1539.                     }
  1540.                     TEClick(pt,(event->modifiers & shiftKey) ? 1 : 
  1541. 0,peek->textH);
  1542.                     return 1;            // Return where I am now. 
  1543.             }
  1544.     }
  1545.     return 0;        // Not one of these; can't deal with it at all...
  1546. }
  1547.  
  1548. - -CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---
  1549.  
  1550. I hope this helps. Permission is granted to use this message and the
  1551. code contained herein in any way you want, redistribute it, fold it,
  1552. spindle it, or mutulate it, so long as you don't sue me if the code
  1553. crashes. Given away as is, without warranty of any kind. If you don't
  1554. like this, my lawyer can mud-wrestle your lawyer in the nude for 15
  1555. rounds at the local mud-wrestling bar for brownies. (This assumes,
  1556. of course, that your lawyer and my lawyer look good in the nude. :-)
  1557.  
  1558.                         - Bill
  1559. -- 
  1560. o William Edward Woody      | "I'm shying from the light
  1561.   In Phase Consulting      |  I always loved the night
  1562.   337 West California #4  |  And now you offer me eternal darkness"
  1563.   Glendale, CA 91203      |          - Depeche Mode, "One Caress"
  1564.  
  1565. ---------------------------
  1566.  
  1567. End of C.S.M.P. Digest
  1568. **********************
  1569.  
  1570.  
  1571.