Page 1 of 1

PostPosted: Thu Aug 23, 2001 6:00 pm
by Dman
Hey, I found a file compression library for the Palm, but it's not specifically for PocketC. Can I use it (with PocketC), or if I can't, how can I make it usable (with PocketC). And How do I make my own PocketC Libraries (I know C++)

PostPosted: Thu Aug 23, 2001 7:54 pm
by jstadolnik
You'll have to write a native library to interface with the compression library.

First read the PocketC native library documentation.

There are two tools sets you can use: Codewarrior ($$$) or gcc/PRC-Tools (free).

If you go with Codewarrior use the PocketClib example which comes with the PocketC desktop distribution.

If you go with gcc/PRC-Tools use the xGrfxLib source as an example.

You can get the gcc/PRC-Tool chain here:

Here is help on setting up the gcc/PRC-Tool chain:

Here is help on compiling native libs with gcc/PRC-Tools (note the fractal lib example will NOT compile with the OS4.0 SDK):

The following places are excellent sources of general palm development information:
1) The online SDK4.0 documentation (your first line of defense):
2) The PalmOS Dev Forum (I find searches here to be especially helpful):
3) The PalmOS knowledge base:

Finally, if you need to pass an array of strings to/from a native library function send Jeremy ( an email and he'll send you a special set of functions for accessing the strings correctly.


Edited by - jstadolnik on 08/23/2001 15:00:27

PostPosted: Mon Aug 27, 2001 10:02 pm
by Dman

PostPosted: Sat Mar 23, 2002 3:03 am
by jstadolnik
Here is a code sample showing a native library function in which integer and string input values are passed back through pointers.


//String structures
enum StrType { stClassic, stIndirect, stConst }; // only used for debugging for now

struct String {
StrType sType;
unsigned int nRef;
char data[1];

//This function shows you how to pass integers and strings in as values and
//out through pointers

void ExampleFunc(PocketCLibGlobalsPtr gP) {

Value int_input, int_output_ptr, str_input, str_output_ptr, *intP, *strP;

String *pString;

//Do integer copy first
intP = gP->deref(int_output_ptr.iVal); //get pointer to int_output
intP->iVal = int_input.iVal; //Copy int_input to int_output

//Do string copy next
char *newdata = (char*)MemHandleLock(str_input.sVal); //get value of input string
gP->retVal->iVal = StrLen(newdata); //set return value to be size of input string
strP = gP->deref(str_output_ptr.iVal); //get pointer to str_output

//Check if string sVal is a MemPtr or a MemHandle
if (0x80000000 & (UInt32)strP->sVal) {
//It's a MemHandle : need to resize the old handle
MemHandleResize(strP->sVal,sizeof(String)+StrLen(newdata)); //change handle size
pString = (String*)MemHandleLock(strP->sVal); //lock handle
else {
//It's a MemPtr : need to allocate a new handle
strP->sVal = MemHandleNew(sizeof(String)+StrLen(newdata)); //change handle size
pString = (String*)MemHandleLock(strP->sVal); //lock handle
pString->sType = stIndirect; //set type of string (currently unused)
pString->nRef = 1; //for string garbage collection

//Copy the string data from str_input to str_output
MemHandleUnlock(strP->sVal); //unlock handle

//unlock str_input
//note: don't need to unlock str_input.sVal if you clean it

The PToolboxLib guy.