Path: utzoo!mnetor!uunet!husc6!think!ames!pacbell!varian!kinetics!markw
From: markw@kinetics.UUCP (Mark Wittenberg)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Writing resources to a file
Message-ID: <600@kinetics.UUCP>
Date: 4 May 88 17:48:43 GMT
References: <51379@sun.uucp>
Distribution: na
Organization: Kintics, Inc., Walnut Creek, CA
Lines: 48

From article <51379@sun.uucp>, by dhare%integral@Sun.COM (Dwight Hare):
> I am writing resources to files for the first time.  The interface for
> this is extremely clumsy.  In short, I do the following:
> 
> 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
> 4) do a Get1Resource of the resource I intend to write
> 5) if the get fails, allocate a handle and do an AddResource
> 6) change the resource
> 7) call ChangedResource with the resource
> 8) do a CloseResFile.
> 
> Two questions:  Is this right?  Do I need to deallocate the handles if I
> allocated them, and if so, how? (DisposHandle or DisposeResource?)
> 
> Thanks,
> Dwight

You must DisposeResource, not DisposHandle.  The latter will cause a later
NewHandle (the next one?) to appear to be a resource ... with interesting
consequences.  BTW, if the Get1Resource succeeds I usually just RemoveResource
it, and then always AddResource.  Be careful that your output resource file
isn't currently open (mustn't close it if it is -- like, the system, your
application, ...).  If you're running on the old ROMs and don't have
Get1Resource, you have to use GetResource and check to see if it's in the
right resource file.  If not, you have to DisposeResource it UNLESS it had
already been gotten.

So, we have two open questions:

1.  How do you tell if a resource file is already open?
    OK, I know you can run through the FCB list, but this doesn't seem like
    a very good idea, from the compatibility point of view.
2.  How do you tell if a resource has already been loaded?  I'd prefer to know
    without loading it, but I'll settle for just knowing whether or not I
    should unload it.  It's not sufficient to call SetResLoad(FALSE) before
    the GetResource, and check to see if the handle was NULL.

Any answers out there?


Mark Wittenberg
Kinetics, Inc.
2500 Camino Diablo
Walnut Creek, CA 94596
(415) 945-3645
UUCP: ucbvax!mtxinu!kinetics!markw