Path: utzoo!attcan!uunet!samsung!olivea!orc!bbn.com!nic!chaos.cs.brandeis.edu!chaos!phils From: phils@chaos.cs.brandeis.edu (Phil Shapiro) Newsgroups: comp.sys.mac.programmer Subject: Re: THINK C Help with Resources Message-ID: Date: 8 Oct 90 14:58:27 GMT References: < <30543@netnews.upenn.edu> <522@skye.cs.ed.ac.uk> Sender: @chaos.cs.brandeis.edu Organization: Symantec Corp. Lines: 30 In-Reply-To: nick@cs.edinburgh.ac.uk's message of 5 Oct 90 10:51:31 GMT In article <522@skye.cs.ed.ac.uk> nick@cs.edinburgh.ac.uk (Nick Rothwell) writes: > In article <30543@netnews.upenn.edu>, gilbert@grad1.cis.upenn.edu (Michael Gilbert) writes: > > I want to store this thing as a resource in a file. So, I first call > > CreateResFile (myFileName); (with appropriate error-checks), and > > then UseResFile (myFileName) to make use of the file. Finally, I use > > > > AddResource ((Handle) myThingHandle ...) > > > > to add the resource. Now, using ResEdit, I can see that the > > resource was indeed added correctly to this file. However, after > > saving this data to the file and closing it, the data in my object is > > corrupted. > > I don't have my copy of Inside Mac to hand, and I haven't actually > written applications which create resources, so this is a rough guess, > but it's possible the handle is getting purged and/or moved as soon > as you flush it to the file. In all my Mac programming, I always wrap > calls to H{Un}Lock and H{No}Purge around anything I'm not certain about. Once you call AddResource, the handle is a resource handle. It belongs to the resource file that you added it to. Once you close the resource file, the handle is no longer valid (all resources in the closed file are deallocated). The solution is to either (1) call HandToHand to copy it, or (2) call DetachResource after adding the handle to the file, but before you close it. (Look at IM I-124). -phil shapiro, symantec tech support -- Phil Shapiro phils@chaos.cs.brandeis.edu