home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 13017 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  2.2 KB

  1. Path: sparky!uunet!wupost!uwm.edu!rutgers!njitgw.njit.edu!tesla.njit.edu!erh0362
  2. From: erh0362@tesla.njit.edu (Elliotte Rusty Harold)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Parameter Types for GetIndString, ParamText, NewString, et al.
  5. Message-ID: <1992Jul25.002622.1@tesla.njit.edu>
  6. Date: 25 Jul 92 05:26:22 GMT
  7. Sender: news@njit.edu
  8. Organization: New Jersey Institute of Technology
  9. Lines: 51
  10. Nntp-Posting-Host: tesla
  11.  
  12.  
  13.     Can anyone spot the problem in the following code? It typically crashes 
  14. at either the GetIndString, the ParamText, or the StopAlert call.  I suspect 
  15. I'm not passing the proper type of argument to one of the toolbox calls (e.g. 
  16. sending a Str255 where I should be passing a StringPtr or vice versa) but I've 
  17. tried this with many different combinations of variable 
  18. type without success.  The various 
  19. sample source I've looked at has been inconsistent on the type of argument 
  20. passed to these toolbox calls, i.e. some pass strings and some pass StringPtr's.
  21. Do I need to allocate space for errorString (a Str255) or is it automatically 
  22. allocated since errorString is really an array of 256 chars?  If I 
  23. do need to allocate space, how?  Can I dispense with the StringHandle 
  24. errorStringH  entirely and just use errorString and &errorString as necessary? 
  25. All suggestions appreciated.  Problem function follows.
  26.  
  27.  
  28. /* returns FAILURE if there is a problem, SUCCESS otherwise */
  29. Boolean IOCheck(OSErr errornumber) {
  30.  
  31.     Str255     errorString;
  32.     StringHandle errorStringH;    
  33.  
  34.     if (errornumber != noErr) {
  35.  
  36.         errorStringH = NewString(&errorString);
  37.         HLock(errorStringH);
  38.         GetIndString(**errorStringH, IO_ERROR_STRINGS, 
  39.             -1 * errornumber - ZEROTH_IO_ERROR );
  40.         if ( errorString == NIL_POINTER) {
  41.           ParamText( HOPELESSLY_FATAL_ERROR, NIL_STRING, 
  42.             NIL_STRING,NIL_STRING);    
  43.         } /* end if */
  44.         else {
  45.           ParamText( *errorStringH, NIL_STRING, NIL_STRING,NIL_STRING) ;
  46.         }
  47.         HUnlock(errorStringH);
  48.         DisposHandle(errorStringH);
  49.         StopAlert(ERROR_ALERT_ID, NIL_POINTER);
  50.     
  51.         return FAILURE;
  52.     } /* end if */
  53.     
  54.     else
  55.         return SUCCESS;
  56.     
  57.  
  58. } /* end IOCheck */
  59.  
  60. Elliotte Rusty Harold        Department of Applied Mathematics
  61. elharo@m.njit.edu        New Jersey Institute of Technology
  62. erh0362@tesla.njit.edu        Newark, NJ 07103
  63.