Path: utzoo!attcan!uunet!mcsun!hp4nl!fwi.uva.nl!dolf From: dolf@fwi.uva.nl (Dolf Starreveld) Newsgroups: comp.sys.mac.programmer Subject: Interesting problem with GetResource('dctb', id) Message-ID: <232@fwi.uva.nl> Date: 5 Nov 89 21:03:22 GMT Sender: news@fwi.uva.nl Reply-To: dolf@fwi.uva.nl (Dolf Starreveld) Organization: FWI, University of Amsterdam Lines: 46 I am currently working on a program that needs to copy a 'dctb' resource from one file to another. Since the program must also copy other resources I have written a general purpose "CopyResource" routine. The routine itself was extensively tested and seemed to work, but ..... The copying of the 'dctb' resource was only recently added and things started to go wrong. After lots of debugging I found out that after executing the following statement: inHandle = GetResource('dctb', 10000); "inHandle" contains a valid handle, but not a handle to a resource. I entered TMON to find out more and: 1) Just before executing the statement the 'dctb' resource is not loaded in the heap. 2) Just after the statement, the 'dctb' resource is loaded, but immediately following it, the heap contains another relocatable block of exactly the same size of the resource (48 bytes). 3) The GetResource call returns a handle to this last block instead of to the actually loaded resource. Since my program continues to do a GetResInfo call on the handle returned, I get into problems. The handle is not a handle to a resource and the call sets ResError != 0. Furthermore, the &resID is set to -1 and the &resType is set to four zero bytes. This is what finally causes another program using the copied resource file to crash. I moved the GetResource call to very early in my program (just after ToolBox initialization), just to be sure the heap was not already corrupt. I also tried using other values for the ID (100 instead of 10000). The net result was the same in all cases: two blocks appear on the heap and the wrong handle is returned to me. Is this a bug in the system software? Am I doing something wrong? Any suggestions? BTW. For those who think it is important, I am using THINK C 4.0 on an 8Mb Mac IIcx, system 6.0.4b15. Before you start screaming about using 6.0.4b15, you should know that the problems were already there when I still used 6.0.3. I have not tested with other versions. --dolf Dolf Starreveld Phone: +31 20 592 5056/+31 20 592 5022, TELEX: 10262 HEF NL EMAIL: dolf@fwi.uva.nl (dolf%fwi.uva.nl@hp4nl.nluug.nl) SNAIL: Dept. of Math. and Computing Science, University of Amsterdam, Kruislaan 409, NL-1098 SJ Amsterdam, The Netherlands