Hi everybody,
Please tell me what I did wrong. I read a database file (PRC or PDB) from PC, put in a
file
stream. If I use MemPtrNew() to allocate buffer and create database using
DmCreateDatabaseFromImage(), my database is OK. That means the data in file stream is
good. I
don't know how big the database would be so I can't actually use MemPtrNew().
If I use ExgDmRead() to create the database, my last record in the new database is
corrupted. I am
asking about this problem before and ExgDBWrite works for me but I can not make
ExgDBRead()
working at all.
Thanks in advances.
tnn
This is my code for DmCreateDatabaseFromImage()
Char *buff;
// ...
buff = (Char *) MemPtrNew(size);
// check for error of MemPtrNew()
// ...
FileRead(fileH, buff, 1,(Int32) size,&err);
err = DmCreateDatabaseFromImage(buff);
MemPtrFree(buff);
// this database is OK !!!
// ....
And this is my code for ExgDBRead.
UInt32 fileSize = 0;
// callback function
static Err ReadFromFile(void* dataP, UInt32* sizeP, void* userDataP)
{
Err err = 0;
UInt32 bytesLeft;
if (*sizeP > fileSize)
*sizeP = fileSize;
*sizeP = FileRead((FileHand)userDataP, (void *)dataP, 1,(Int32) *sizeP,&err);
bytesLeft = fileSize - *sizeP;
if (!bytesLeft)
*sizeP = 0; // by returning 0 in *sizeP, ExgDBRead () will stop reading
else
fileSize = bytesLeft;
return (err);
}
static Boolean DeleteOldDB(const Char *dbName, UInt16 dbVersion, UInt16 whichCard,
LocalID dbID,
void* userDataP)
{
return (true);
}
Err CreateDBFromFile(FileHand fileH,UInt32 size)
{
// ...
LocalID dbID;
UInt16 whichCard = 0;
// ... for now, I look for the duplicate and delete it to make the DeleteOldDB()
callback function
simple
// ... delete database if there is duplicated
// ...
fileSize = size;
err = ExgDBRead(ReadFromFile, DeleteOldDB,(void *)fileH, &dbID, whichCard, false,
true);
// err return from ExgDBRead() is 0,
//...
return (err);
}
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/