[comp.sys.mac.programmer] Creating Resources???????

mikeoro@hubcap.UUCP (Michael K O'Rourke) (02/18/89)

I am trying to create and read from a resource to store user preferences.
I created a data structure with two booleans and two inits.  All the data
writes out fine, but when I try to read it back in it gets messed up.

Volume 1 talks about header, application and reserved data at the beginning
of a resource. I'm not expected to write this out as part of my data structure
am I?  I can't figure out what's going on.

Michael O'Rourke

tim@hoptoad.uucp (Tim Maroney) (02/19/89)

In article <4481@hubcap.UUCP> mikeoro@hubcap.UUCP (Michael K O'Rourke) writes:
>I am trying to create and read from a resource to store user preferences.
>I created a data structure with two booleans and two inits.  All the data
>writes out fine, but when I try to read it back in it gets messed up.
>
>Volume 1 talks about header, application and reserved data at the beginning
>of a resource. I'm not expected to write this out as part of my data structure
>am I?  I can't figure out what's going on.

Sounds like you're using File Manager I/O when you should be using
Resource Manager I/O.  Use CreateResFile to make the file to store the
resource, if it doesn't exist already, then use AddResource to add the
resource to the file if it doesn't exist already.  If you do this, you
can ignore the section on the resource file format with the stuff about
headers etc.
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"Next prefers its X and T capitalized.  We'd prefer our name in lights in
 Vegas."  -- Louis Trager, San Francisco Examiner

mikeoro@hubcap.UUCP (Michael K O'Rourke) (02/19/89)

In article <6569@hoptoad.uucp>, tim@hoptoad.uucp (Tim Maroney) writes:
> In article <4481@hubcap.UUCP> mikeoro@hubcap.UUCP (Michael K O'Rourke) writes:
> >I am trying to create and read from a resource to store user preferences.
> >I created a data structure with two booleans and two inits.  All the data
> >writes out fine, but when I try to read it back in it gets messed up.
> 
> Sounds like you're using File Manager I/O when you should be using
> Resource Manager I/O.  Use CreateResFile to make the file to store the

Nope, I'm using the resource manager. I am using creatresfile and addresource
just like you said, but it doesn't work. As I said, it writes everything out
peachy keen. However, on reading in back it things get mucho fouled up.


michael o'rourke
clemson university

tim@hoptoad.uucp (Tim Maroney) (02/19/89)

In article <4481@hubcap.UUCP> mikeoro@hubcap.UUCP (Michael K O'Rourke) writes:
>I am trying to create and read from a resource to store user preferences.
>I created a data structure with two booleans and two inits.  All the data
>writes out fine, but when I try to read it back in it gets messed up.

In article <6569@hoptoad.uucp>, tim@hoptoad.uucp (Tim Maroney) writes:
> Sounds like you're using File Manager I/O when you should be using
> Resource Manager I/O.  Use CreateResFile to make the file to store the

In article <4487@hubcap.UUCP> mikeoro@hubcap.UUCP (Michael K O'Rourke) writes:
>Nope, I'm using the resource manager. I am using creatresfile and addresource
>just like you said, but it doesn't work. As I said, it writes everything out
>peachy keen. However, on reading in back it things get mucho fouled up.

Oh darn.  Well then, to answer your initial question, no you don't need
to put a header and so forth on your resource.  There are really any
number of things that could create this problem; most of them could be
eliminated by calling WriteResource directly after you call AddResource.

What seems most likely is that you're forgetting that the resource
handle becomes sacred after you pass it to AddResource.  That is, the
system handles it from that point.  If you call DisposeHandle or
otherwise overwrite it or mess with it in any way other than with
Resource Manager calls after that, you're asking for trouble.  Best to
add it and then have your software ignore the fact that it still
exists; let the system take care of it.
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"The time is gone, the song is over.
 Thought I'd something more to say." - Roger Waters, Time

topping@laurel.cis.ohio-state.edu (brian e. topping) (02/21/89)

[lots of stuff on RM bugs deleted ...]

I don't know if this helps, but I had a real tough RM bug come and go
that was caused by not checking the return codes on each time back.  I
had just created the file, added a res, and then deleted a res.  I think 
the handle I tried to delete was not a res, and then the resources I had
written earlier (even with _WriteResource) got cleared to an empty resource.

Have you tried examining the resource with resedit?  Sounds stupid, I know,
but I just remember the hell I went through trying to kill that one... -bri