Re: Newbie question: error in creating a NSData object using handle (Resource Management)
Re: Newbie question: error in creating a NSData object using handle (Resource Management)
- Subject: Re: Newbie question: error in creating a NSData object using handle (Resource Management)
- From: Kai <email@hidden>
- Date: Wed, 25 Jun 2008 08:36:13 +0200
Hi,
"I GOT AN ERROR HERE" may be a little too unspecific. Perhaps you can
elaborate: crash, exception, nil return, Console entry, what else?
That said, you should use GetHandleSize (dataHandle) instead of
GetResourceSizeOnDisk(dataHandle). GetResourceSizeOnDisk() can return
values which are too large (see documentation).
Ah, and I just see that you combinded CountResources with
Get1IndResource, that’s probably wrong. You should use CountResources
with GetIndResource or Count1Resources with Get1IndResource.
Neither of this directly explains the difference between using NSData
and the direct copy. But since you potentially access non existing
bytes or data, that may be coincidence.
Best
Kai
Hi folks,I'm a newbie to Cocoa.
Recently, I'm working on a project relating to Resource Management.
In my project, there's a part that I'm reading through the resources
in a
resource file.
I'm using:
int count = CountResources( typeName );
to get all resource that has the type "typeName", then loop through
this
resource list to take resource data out.
for (n = 1; n <= count; n++)
{
Handle dataHandle = Get1IndResource( type1, n);
....
NSData *data = [NSData dataWithBytes: *dataHandle length:
GetResourceSizeOnDisk(dataHandle)]; // I GOT AN ERROR HERE
//using data
struct A_STRUCT aStruct;
memcpy(& aStruct,[data bytes], [data length]);
}
After several times looping through the list, I got an error in the
line
above.
But if I use data directly, like the following code, there is no error
occurred.
memcpy(&pgControlRes,*dataHandle, GetResourceSizeOnDisk(dataHandle));
Any suggestions for my problem.
I highly appreciate all your helps.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden