grae@murdu.OZ (Graeme Gerrard) (07/06/88)
I am working on an application for on a MacII in C, and have a problem with directories and files. Actually I have more than one problem, but for all I know they may be related. Here's what I want to do: (1) open 2 files in a directory selected by the user with SFGetFile. (2) open a file for writing in a specific directory using SFPutFile, but I want to set the directory before SFPutFile puts up its dialog box. (3) ...the application runs... (4) open the resource fork of my output file and write some info about it there as a STR#. Here's my code for setting the directory before calling SFPutFile. **I only know the full path name of the directory** SetSFDir(dirName) char *dirName; { OSErr errnum; char mystr[64]; WDPBRec myWDParamBlk; extern long SoundFileDirID; extern long SaveTheDir; SaveTheDir = CurDirStore; strcpy(&mystr, dirName); CtoPstr(&mystr); myWDParamBlk.ioNamePtr = (StringPtr)mystr; myWDParamBlk.ioCompletion = 0L; myWDParamBlk.ioVRefNum = 0; myWDParamBlk.ioWDDirID = 0L; if ( (errnum = PBHSetVol(&myWDParamBlk, FALSE)) != noErr ) { PtoCstr(&myWDParamBlk.ioNamePtr); OSError("SetSFDir error: PBHSetVol", myWDParamBlk.ioNamePtr, (long)errnum); return(FALSE); } PBHGetVol(&myWDParamBlk, FALSE); SoundFileDirID = myWDParamBlk.ioWDDirID; CurDirStore = SoundFileDirID; return(TRUE); } Well, everything seems to work fine as it is, till the program gets back to the main loop. If I click anywhere in the menu bar I get the BIG BOMB with 01 or 03. If I take out the set initial directory business and just use SFPutFile to find my directory, everything runs fine and there are no problems. Now, I have read TechNote #140 about the dangers of using PBHSetVol, but my eyes just glaze over. Hence, I, a mere mortal and novice Mac programmer, blame PBHSetVol - but it could be circumstantial. (I have been able to get the DirID of the directory with just the ioNamePtr using PBGetCatInfo, but it doesn't set the dir so I can open the resource fork as in step 4 above.) Can anybody throw some light on this. How do you safely change the dir that SFPutFile initially looks in and still be able to have valid paths to the files you are using in other directories? Thanks in advance, Graeme Gerrard **************************************************** Graeme Gerrard, Faculty of Music, University of Melbourne, AUSTRALIA. ACSnet: grae@murdu.oz.au ****************************************************
darin@Apple.COM (Darin Adler) (07/08/88)
In article <1409@murdu.OZ> grae@murdu.OZ (Graeme Gerrard) writes: > Now, I have read TechNote #140 about the dangers > of using PBHSetVol, but my eyes just glaze over. Hence, I, a mere mortal > and novice Mac programmer, blame PBHSetVol - but it could be circumstantial. > (I have been able to get the DirID of the > directory with just the ioNamePtr using PBGetCatInfo, but it > doesn't set the dir so I can open the resource fork as in step 4 above.) Well, one thing I can tell you right away is that OpenResFile (or OpenRFPerm) and PBHSetVol do *not* get along, as TN 140 mentions. Calling PBHSetVol and then trying to use OpenResFile is no use! OpenResFile will ignore the dirID component of the current directory. You *must* open a working directory before opening a resource file in that directory (with OpenRFPerm). Some of this will probably be alleviated with the new glue in MPW 3.0, which may include a new routine, HOpenResFile, that allows you to open a resource file in a directory without creating a working directory with OpenWD. Darin Adler AppleLink: Adler4 UUCP: {sun,voder,nsc,mtxinu,dual}!apple!darin CSNET: darin@Apple.com