I believe that your problem may be in the reading of the record, not
writing. When you create the record you are writing:
long, short, char[sizeof(str)+1]
However, if you try to read the record using your NotesRecord structure you
are expecting:
long, short, char *
In this case you are expecting the four bytes after the short to be the
_address_ of a string in memory. Your record actually contains the first
four bytes of the string. Redeclaring NotesRecord as:
typedef struct
{
long OrderNumber;
short Type;
Char Text[1];
} NotesRecord;
Would make the structure match your writing method. Note that the size of 1
for the Text element is just a place holder so that 'Text' can be used as a
const pointer to the actual string data embedded in your record.
Good Luck,
-jjf
-----Original Message-----
From: Mark W. Alme [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 30, 2000 10:24 AM
To: Palm Developer Forum
Subject: Help with DmStrCopy
When I execute the following, the Text field of the record is filled
with garbage. I've looked all over to find a possible solution, but
haven't found anything.
Do I need to pack the record (a la Palm Prog. the Definitive) even
though there's a single string field?
Any help is much appreciated.
Mark
// begin code snippet
typedef struct
{
long OrderNumber;
short Type; // the types defined below
CharPtr Text;
} NotesRecord;
Boolean NoteWriteRecord(long order, short type, const Char* pText){
UInt length = 0;
UInt offset = 0;
Handle hRec;
NotesRecord *ptr;
Err error;
int index = NoteGetIndexByApptType(order, type);
length = sizeof(order) + sizeof(type) + StrLen(pText) + 1; // null term
if (index > -1) { // get a handle to the record
hRec = DmResizeRecord(gNotesDB, index, length);
} else { // create a new record
index = 0;
hRec = DmNewRecord(gNotesDB, (UInt *)&index, length);
}
// write the data to the record
if (hRec) {
ptr = (NotesRecord *)MemHandleLock(hRec);
DmWrite(ptr, offset, &order, sizeof(order));
offset += sizeof(order);
DmWrite(ptr, offset, &type, sizeof(type));
offset += sizeof(type);
error = DmStrCopy(ptr, offset,(CharPtr)pText);
MemHandleUnlock(hRec);
return true;
} else {
// non-fatal display the error
return false;
}
// release the record
NoteReleaseRecord(index, true);
}
--
Mark W. Alme
Analyst
Alme & Associates
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/