bartop

palmoswerks ARCHIVE
Palm OS programming tips from a (former) CodeWarrior insider

header

Navigation

Search
Home
About
Stories
Stuff I Like
Articles
PilRC
CodeWarrior
palmos.techwood.org
DevTools List
Palm OS Dev FAQ

Stuffing Data into Resources

Back in one of my earliest articles here, I talked about how to store data into your programs, and I alluded to another technique where you directly pulled data from a file into a resource. I never returned to that topic, but since I've just used it in a program I'm writing, I thought I'd finally talk about it here.

To do this, you need to use Rez-format resources. Rez is the Apple resource compiler used for classic Mac OS applications, and also used by Palm OS programmers to build resources for their applications. Most resources get translated directly, while some get processed by the PalmRez post linker into other Palm OS specific forms. CodeWarrior for Palm OS includes the Rez compiler in both its Mac and Windows versions, so don't be discouraged if you're on Windows.

For my application, I needed to take some PDB files I had in my project directory and include them as parts of my program. At runtime, I was going to use a call to DmCreateDatabaseFromImage to recreate the Palm OS databases from the resources.

The syntax isn't too hard. You use the read command to pull in a source file and assign it to a resource type and ID. In my application, my Rez file looked like:

read 'iPDB' (1000) "band_info.pdb";
read 'iPDB' (1001) "band_time.pdb";
read 'iPDB' (1002) "band_panel_info.pdb";
read 'iPDB' (1003) "band_panel_time.pdb";

The 'iPDB' was just a type I made up to designate an included PDB file. The number is parenthesis is the ID number for these resources, then the name in quotes was the file to include verbatim. The Rez compiler will search your access paths for this file.

There are some other options you can use here. If you want to find out more about Rez, you need to go to developer.apple.com and download the manual Building and Managing Programs in MPW. There is a whole chapter on the Rez language there. Not all of Apple's Rez syntax works perfectly in CodeWarrior; I was able to crash the Rez compiler and IDE using a complicated $$format expression.

brought to you by weblogger.com


Send feedback to combee@techwood.org
Copyright © 2004 Benjamin L. Combee
Palm OS is a registered trademark of PalmSource, Inc.
Metrowerks and CodeWarrior are registered trademarks of Metrowerks Inc.

The views expressed on this website/weblog are those of mine alone and do not necessarily reflect the views of PalmSource or Metrowerks.

This is a Manila Site

qwertYAK / frobnovich