From: cole@alexia.lis.uiuc.edu (Sandra Stewart-Cole)
Subject: HELP! INIT and patching probs
Organization: University of Illinois at Urbana
Date: Wed, 30 Dec 1992 20:34:36 GMT

        I have got a problem. It seems that what I thought about resources and
resource files and INIT time and how they all work together wasn't right, and I
can't seem to find a decent workaround. 
        The central problem is that I've got an INIT that installs some trap 
patches for various tasks (primarily a patch to PrGlue and one to SystemTask so
I can get regular frequent cpu time without VBL hassles) and I need these 
patches to have access to some resources (alerts and dialogs being the chief 
need) but I found no supported way to either find my own filename as an INIT, 
or to lock open the INIT's file so that I have a resource map to let resource 
calls work with. As a result, I tried to instead create a temp file that I 
could reliably find, and load it up with the resources I might need. The code 
that did this is below; variable names have been made absurdly descriptive, and
I've removed all of the error checking code, that wasn't showing me errors 
anyway with one exception noted below:
 
        INITfilerefnum=CurResFile();
        GetVRefNum(INITfilerefnum, ThisVRefNum);
        RHandle1=GetResource( 'DITL', 128);
        RHandle2=GetResource( 'DLOG', 128);
                        .                  // a series of GetResource calls
                        .
                        .
        DetachResource(RHandle1);
                        .                 // a series of DetachResource calls
                        .
                        .
        CreateResFile("\pTempFile");
        TempRefNum=OpenResFile("\pTempFile");
        AddResource(RHandle1,'DITL',128,"");
        SetResAttrs(RHandle1,resSysHeap+resPurgeable);
                        .  // a series of AddResource and  SetResAttrs calls
                        .
                        .
        CloseResFile(TempRefNum);
 
 
        The one error I OCCASIONALLY got was one not expected from the resource
manager, a -34 error. The only reference I can find for that is a File Manager
disk full error, but that doesn't make any sense, since the disk in question 
had a few hundred Kb free, and the total size of my resources was under 3Kb. 
The file I got as a result of this was badly munged, with ResEdit unable to 
repair it sufficiently to even see one undamaged resource. Later attempts (from
my SystemTask patch) to read resources (thru GetNewDialog) weren't pretty. I 
did confirm that a valid resource file (created with ResEdit mimicing what I 
was trying to do above) worked perfectly.
        The result of fiddling with this for a few hours was that I have 
resorted to hunting down an undocumented (as far as I can find) feature of the
INIT process. It seems that a pointer to the INIT filename is stashed in low 
memory at 0x914 (CurApName+4) and this will let me find my original file just 
fine.
        My questions are these: 1. Is there any DOCUMENTED and SUPPORTED way to
get enough info about a file solely from the fact that it is the current 
Resource file that I can then regain a path to it after I have been cut loose 
from it  WITHOUT relying on System 7 features? (i.e. get the info in the INIT,
and store it for later use from a global trap patch) 2. Why did my attempt to 
create a file I could find easily fail, and why did I get the -34 error?