[futurebasic] Re: Creating resources from scratch

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 1998 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sat, 30 May 1998 11:14:09 -0500
Terence wrote:
> I've got a routine that will read data from the data fork into a handle.
> Now what I want to do is to create a new resource file, from scratch, and
> place the data fork data from the first file, into, say, restype _"TJTJ",
> ID% = 1024, and name it "Terence's Resource".
> 
> here's basically what I've been trying(psuedo):
> OPEN data fork of "output.rsrc" (my new from scratch file)
> CLOSE data fork 'creates the file with 0 data, but it's still there.
> fn pGReplaceXRes(mydataforkresourcehandle,_"TJTJ",1024,"Terence's
> Resource",RFnum)
> 
> But when I open the output file with resedit, it's either, "No Resource
> Fork, would you like to create one?" or "This file is corrupted, Error
> #-193"

One thing you need to remember is that these things which we call the
data "fork" and the resource "fork" are actually two separate files. 
Sort of.  The MacOS treats them as a _single_ file when you delete
it/them, or when you move it/them to another folder, or when you rename
it/them.  But they are _created_ separately.  Creating a data fork does
not create a resource fork, and creating a resource fork does not create
a data fork.

So, when you creat a file from scratch using FB's command OPEN
"O"...you're creating the data file (fork, whatever), but you're not
creating the resource file.  You need a separate command to do that. The
easiest way is like this:

  CALL HCREATERESFILE(vRefNum%, 0, filename$)

You do not need to use the OPEN "O"...statement at all, unless you want
your file also to have a data fork.

FB's OPEN command can create and open a (data) file in a single step,
but to create and open a resource file, it takes two steps: first you
create the file (as above), then you open it, using another statement
like this:

  RFnum = FN HOPENRESFILE(vRefNum%, 0, filename$, _fsRdWrPerm)

(the _fsRdWrPerm parameter says that you want exclusive read/write
access to the file--there are other possibilities too).  If the file was
opened successfully, then a reference number is returned in RFnum. 
That's the number that you should pass in the last parameter to FN
pGReplaceXRes (I'm curious to know exactly what number you _were_
passing in there, since you apparently were not actually creating or
opening a resource file).

After you call FN HOPENRESFILE, you should always check the value of
RFnum.  If it's -1, that means that the file could not be opened
(because, for example, it doesn't exist yet).

Finally, when you're ready to close the resource file, use this:

  CALL CLOSERESFILE(RFnum)

Hope this helps.

- Rick