Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!dogie.macc.wisc.edu!vms.macc.wisc.edu From: yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) Newsgroups: comp.sys.mac.programmer Subject: Config File Resource Blues Message-ID: <2002@dogie.macc.wisc.edu> Date: 8 Jul 89 03:11:19 GMT Sender: news@dogie.macc.wisc.edu Organization: University of Wisconsin Academic Computing Center Lines: 71 I'm having problems maintaining a configuration file for my application. It lives in the System Folder and is a file w/a resource fork containing some data that gets read in when I open a certain type of document window in my app, and then gets written out when I close the window. My problem is when I re-open the window in the same session, and try to reread the resource, the GetResource call goofs up. Below are two code fragments, ReadConfig() gets called when I open my document, the first time it's called it works fine, GetResource returns a handle that points to my data, and dataLen is correct. Then when I close the document I call WriteConfig. The data that I'm maintaining may have changed and the config file data would therefore be out of date, so I automatically clear it, create a new handle, stream my data into the handle, and add the resource. If I quit my app at this point and examine my config file w/ResEdit, the data looks hunky-dory. But if I instead try to reopen my document window, thereby calling ReadConfig again, the GetResource mysteriously returns some bogus handle (I think) that points to nothing significant, and dataLen is bad as well. ResError() never returns a bad value, to the best of my knowledge. The value of CurResFile() never changes when I check it a various locations around this code. The config file is opened at the program start by a call to OpenResFile, which is set to look in the System Folder. I'm not doing anything significant, I guess, between opening, closing, and then opening my document. Any ideas/comments? ReadConfig() { Handle dataHdl; long dataLen; dataHdl = GetResource('DATA', 128); dataLen = SizeResource(dataHdl); /* At this point I stream the data into * a application maintained structure. This * data may change as the user interacts * w/the app. */ } WriteConfig() { Handle dataHdl; Handle aHdl; /* Zap the old data as it is most likely out of date */ dataHdl = GetResource('DATA', 128); RmveResource(dataHdl); WriteResource(dataHdl); DisposHandle(dataHdl); aHdl = NewHandle(DATA_SIZE); /* At this point I init aHdl w/the data structure * that I've maintained, in preparation for * writing it back out. */ AddResource(aHdl, 'DATA', 128, ""); WriteResource(aHdl); DisposHandle(aHdl); } //////////////////////////////////////////////////////////// Internet: yahnke@macc.wisc.edu Phonenet: 608.262.8626 Mailnet: 1210 W. Dayton St., Madison WI, 53706 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\