lotus



previous page: 3.6) What about pre-emptive multitasking? (User / Machine interaction - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 4.2) When can I use the HOpen, HCreate etc file calls? Are they only System 7 calls? (Files - Mac Programming)

4.1) How do I tell fopen() to open a file the user has selected using StandardGetFile? (Files - Mac Programming)




Description

This article is from the Mac Programming FAQ, by Jon Watte h+@austin.metrowerks.com with numerous contributions by others.

4.1) How do I tell fopen() to open a file the user has selected using StandardGetFile? (Files - Mac Programming)

The "standard" ANSI C file functions are less than well suited for
the Macintosh way of doing things. However, if you are doing a port for
your own enjoyment and benefit (or maybe for in-house work) you can use
the following function: (see below about converting a wdRefNum into a
vRefNum/parID pair)

*code*
FILE *
fopen_mac ( short vRefNum , long parID , char * fileName , char * mode ) {
  
short oldVol ;
short aVol ;
long aDir , aProc ;
FILE * ret = NULL ;
  
    if ( GetVol ( NULL , & oldVol ) ) {
        return NULL ;
    }
    if ( GetWDInfo ( oldVol , & aVol , & aDir , & aProc ) ) {
        return NULL  ;
    }
    if ( HSetVol ( NULL , vRefNum , parID ) ) {
        return NULL ;
    }
    ret = fopen ( fileName , mode ) ;
    if ( HSetVol ( NULL, aVol , aDir ) ) {
        /* an error we can't currently handle */
    }
    if ( SetVol ( NULL, oldVol ) ) {
        /* an error we can't currently handle */
    }
    return ret ;
}
*end*

All of the above is necessary for one reason or another - if you are
interested, by all means look HSetVol up in Think Reference 2.0 or New
Inside Mac: Files.

In older versions of MPW; this wouldn't work since the MPW libraries
used to do a GetVol and explicitly use that value by itself.

 

Continue to:















TOP
previous page: 3.6) What about pre-emptive multitasking? (User / Machine interaction - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 4.2) When can I use the HOpen, HCreate etc file calls? Are they only System 7 calls? (Files - Mac Programming)