[comp.sys.mac.programmer] Setting directories

grae@murdu.OZ (Graeme Gerrard) (06/20/88)

I am working on an application for 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 given directory. Using SFGetFile - the
	    user chooses the directory and input file name. This file
	    name is used as a prefix for another file in the same
	    directory to which I write comments and debug statements
	    as the application runs along.
	(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) do a whole bunch of stuff.
	(4) open the resource fork of my output file (as in 2) 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;
	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);
		OSError2("SetSFDir error: PBHSetVol",
			myWDParamBlk.ioNamePtr, (long)errnum);
		return(FALSE);
	}
	PBHGetVol(&myWDParamBlk, FALSE);
	SoundFileDirID = myWDParamBlk.ioWDDirID;
	CurDirStore = SoundFileDirID;
	return(TRUE);
}

Now, I have read TechNote #140 about the dangers of using PBHSetVol,
but my eyes just glaze over. (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, 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. Hence, I, a mere mortal and novice Mac programmer,
blame PBHSetVol - but it could be circumstantial.

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?


****************************************************
Graeme Gerrard, Faculty of Music, University of Melbourne, AUSTRALIA.
grae@murdu.oz.au
****************************************************