Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!amdahl!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: Writing resources to a file Message-ID: <9496@apple.Apple.Com> Date: 10 May 88 21:04:59 GMT References: <51379@sun.uucp> Reply-To: lsr@apple.UUCP (Larry Rosenstein) Distribution: na Organization: Advanced Technology Group, Apple Computer Lines: 36 In article <51379@sun.uucp> dhare@sun.UUCP (Dwight Hare) writes: > >1) Do a GetFInfo of the file to see if it already exists >2) if it doesn't, do a PBCreate >3) do an openresfile of the file There are 2 things wrong here. First, on the Hierarchical File System, certain calls (including GetFInfo) will automatically search the System Folder if the file is not found in the first place you specify. So step 1 could actually find a file with the same name in the System Folder. You can always suppress the searching by specifying a dirID and using the HFS-specific calls (eg, PBHGetFInfo). In this particular case, you can also do the Create first, and look at the result. Create does not use the search path. If Create returns an dupFNErr, then the file exists. The second problem is that after the Create, you have to call CreateResFile. CreateResFile initializes the resource fork, which is different than a resource fork with nothing in it. >Two questions: Is this right? Do I need to deallocate the handles if I >allocated them, and if so, how? (DisposHandle or DisposeResource?) There is no DisposeResource. ReleaseResource frees the data taken by a resource. DetachResource disassociates a handle from its resource file, but doesn't free the storage. (Such a handle could be added to another resource file, and should be freed with a call to DisposHandle.) -- Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 27-AJ Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr