home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18738 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.6 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!ucsbcsl!engrhub.ucsb.edu
  2. From: aksguest@engrhub.ucsb.edu (Leonard Cuff)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: No CMGetRefCon inside serial completion routine?
  5. Message-ID: <6804@ucsbcsl.ucsb.edu>
  6. Date: 21 Nov 92 00:08:44 GMT
  7. Sender: root@ucsbcsl.ucsb.edu
  8. Organization: University of California, Santa Barbara
  9. Lines: 38
  10.  
  11. I'm writing a program to process data from a scanner using the Comm Toolbox.
  12.  
  13. It appears that CMGetRefCon cannot be used inside a completetion routine when doing serial I/O.  I have discovered the first code snippet below works, and the
  14. second one doesn't.  I find it difficult to believe the CMGetRefCon allocates
  15. memory, or does anything else too dastardly to mention in a completion routine
  16. (In fact I hardly see the point for having it at all, but I was trying to be
  17. a good Macintosh citizen and use it anyway...)  Any thoughts or comments?
  18. Please email me, I can't quite manage to keep up with this newsgroup.  I'll 
  19. post a summary if folks express interest.
  20.  
  21. void
  22. finish_read(ConnHandle my_conn ) {    // This one works
  23.     Port    *thePort;
  24.     
  25.     thePort = (Port *) (**my_conn).refCon;
  26.     
  27. // The following two lines are
  28. // specific to the data structure pointed to by my refcon 
  29.  
  30.     thePort->valid = TRUE;  
  31.     thePort->ib_length = ((**my_conn).asyncCount)[cmDataIn];
  32. }
  33.  
  34. void
  35. finish_read(ConnHandle my_conn ) {    // This one trashes memory 
  36.     Port    *thePort;
  37.     
  38.     thePort = (Port *) CMGetRefCon(my_conn); 
  39.     
  40. // As above, the following two lines are
  41. // specific to the data structure pointed to by my refcon 
  42.  
  43.     thePort->valid = TRUE;  
  44.     thePort->ib_length = ((**my_conn).asyncCount)[cmDataIn];
  45. }
  46.  
  47. Thanks,
  48. Leonard
  49.