"ThuNguyet Nguyen" <[EMAIL PROTECTED]> wrote in message
news:40254@palm-dev-forum...
> /* FUNCTION: ReadFromFile */
> /* */
> /* DESCRIPTION: Call back function for exchange manager function */
> /* ExgDBRead to read data from file streaming, put in RAM */
> /* */
> /* PARAMETERS: dataP - bufffer containing data to put in file */
> /* sizeP - number of bytes to put in file */
> /* userDataP - application defined buffer for context */
> /* (holds exgSocket when using ExgManager */
This function reads from a file into a buffer provided by the caller. Your
comments are contradictory. Also, the userDataP field is being used to hold
the file stream, not a socket.
> if (totalBytesRead) {
> if (*sizeP > totalBytesRead)
> *sizeP = totalBytesRead;
> FileRead((FileHand)userDataP, (void *)dataP,(Int32) *sizeP, 1,&err);
> ErrFatalDisplayIf(err," FileRead() error");
> totalBytesRead -= *sizeP;
> }
The variable totalBytesRead is really the number of bytes remaining, not the
number that have been read.
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.
The prototype for FileRead is:
Int32 FileRead (FileHand stream, void* bufP, Int32 objSize, Int32
numObj, Err* errP);
so your call should look like:
*sizeP = FileRead((FileHand)userDataP, (void *)dataP, 1, *sizeP, &err);
"objSize" is the size of the "objects" that you're reading from the file.
Since you're counting off bytes, this is 1. The result is the number of
bytes that were read. This needs to be passed back via sizeP. You might want
to get a little fancier in terms of error handling.
ExgDBRead will return whatever non-zero error code you return from your
callback function. This might be where the memErrInvalidParam is coming
from. To find out, add a line at the end of your callback:
ErrFatalDisplayIf(err == memErrInvalidParam, "callback returning
memErrInvalidParam");
This is just for debugging. Note that ExgDBRead could be producing the error
itself as well.
--
Danny Epstein
OS Engineer, Palm Inc.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/