Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!munnari!murdu!grae
From: grae@murdu.OZ (Graeme Gerrard)
Newsgroups: comp.sys.mac.programmer
Subject: Setting default directories
Message-ID: <1409@murdu.OZ>
Date: 6 Jul 88 04:06:43 GMT
Organization: Comp Sci, Melbourne Uni, Australia
Lines: 72


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
****************************************************