Yah I am corrupting my stack, sure of that but then here is my question. This isn't a
palm question but more a C question and I am just having a brain fart. So.....
my struct I want to save --- pszMessage will be longer than 1 char but don't know how
long
typedef struct tag_DebugMessage
{
Char szTime[timeStringLength];
Char szDate[dateStringLength];
Int16 iLevel;
Char pszMessage[1];
} DEBUGMESSAGE, *pDEBUGMESSAGE;
Saving my struct
pszMessage = "A debug message here"; // or something
UInt16 uiTotalSize = sizeof(DEBUGMESSAGE) + StrLen(pszMessage) + 1;
VoidHand vhDBRecord = DmNewRecord(hHandle, &index, uiTotalSize);
if(vhDBRecord)
{
VoidPtr vpszID = MemHandleLock(vhDBRecord);
if(vpszID)
{
Err iErr = DmWrite(vpszID, 0, &DebugMessage,
sizeof(DEBUGMESSAGE));
Int16 ipMessageLen = StrLen(pszMessage);
iErr = DmWrite(vpszID, sizeof(DEBUGMESSAGE) - 2, pszMessage,
StrLen(pszMessage) + 1);
bReturn = true;
MemHandleUnlock(vhDBRecord);
DmReleaseRecord(hHandle, index, true);
}
}
reading my struct
pDEBUGMESSAGE pszLocalData;
Int16 iLen = MemHandleSize(hRecord);
pszLocalData = (pDEBUGMESSAGE)MemHandleLock(hRecord);
I see all my data but when I leave the scope of my function, it blows up. I understand
why the stack is getting clobbered but don't know how to fix it. Since I don't know
how long my debug message are how can I allocation the memory. I can save the size and
then allocation but should I? Doesn't the MemHandleLock do that for you? Sorry for my
ignorance. I could do this a easier way but I want to know what I doing wrong.... btw,
I have a do a -2 on my second DmWrite or when I read the data, the info isn't lined
up. Is this a byte alignment issue?
thanks
Ralph Krausse
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/