Thank you Danny for helping me with this problem.
I still have the same error, please help me.
>This function reads from a file into a buffer provided by the caller.
Is "the caller" ExgDBRead()?
So don't I have to allocate memory for this buffer? If I have to provide the buffer,
how big do I
have to allocate it?
>Your comments are contradictory. Also, the userDataP field is being used to hold the
>file
>stream, not a socket.
Yes, my mistake of cut and paste :(
This is the code I modify as Danny told me to do, Error checking is just for debugging.
// call back function
static Err ReadFromFile(void* dataP, UInt32* sizeP, void* userDataP)
{
Err err = 0;
Char tempstr[32];
if (totalBytesLeft) {
if (*sizeP > totalBytesLeft)
*sizeP = totalBytesLeft;
*sizeP = FileRead((FileHand)userDataP, (void *)dataP, 1,(Int32) *sizeP,&err);
if (err) {
StrPrintF(tempstr," FileRead() error = %d",err);
ErrFatalDisplayIf(true,tempstr);
}
totalBytesLeft -= *sizeP;
if (*sizeP == 0)
ErrFatalDisplayIf(totalBytesLeft," More data when *sizeP = 0");
}
ErrFatalDisplayIf((err == memErrInvalidParam)," call back return
memErrInvalidParam");
return (err);
}
Err CopyDBToPalm(FileHand fileH,UInt32 size, Int16 whichCard)
{
//...
// delete old DB if needed
// totalBytesLeft = size;
FileTell(fileH,(Int32 *) &filesize,&err);
totalBytesLeft = filesize;
err = ExgDBRead(ReadFromFile, DeleteOldDB,(void *)fileH, &dbID, (UInt16)whichCard,
false,
true);
if (err) {
StrPrintF(tempstr," ExgDBRead() error = %d",err);
ErrFatalDisplayIf(true,tempstr);
}
//...
return (err);
}
In the callback function ReadFromFile():
I don't really understand the callback function,
>If you're asked to get n bytes, where n > 0, but you're out of data, you
>need to indicate that by zeroing *sizeP.
How do I know that I am out of data in the callback function with FileRead()?
I don't have any control of the input parameters "dataP" and "sizeP" in the callback
function, do
I?
FileRead() hits EOF and return error first or return *sizeP = 0 first?
In the CopyDBToPalm() function:
The input parameter "size" is taken from the YModem transfer thru serial port. It is
the exact
size of the PRC or PBD on PC.
"filesize" that I get back from FileTell() is always greater than "size". Why are they
different?
I suppose that is the header of file streaming in Palm.
Should I read "filesize" bytes or just "size" in the callback function?
Before, I assign
totalBytesLeft = size;
Now, I assign
totalBytesLeft = filesize;
Either way, I get the error after ExgDBRead(), " ExgDBRead() error = 259"
(memErrInvalidParam).
Do I make mistake when I use ExgDBRead() and the callback function?
Is the data I get from file stream invalid, so I can not create a database from it?
What can I try to fix this bug?
Thanks in advances.
tnn
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/