On Fri, 19 Oct 2001, gordingin wrote:

> typedef struct tag_DebugMessage
> {
>       Char            szTime[timeStringLength]; 
>       Char            szDate[dateStringLength];
>       CharPtr         pszMessage;
> 
> } DEBUGMESSAGE, *pDEBUGMESSAGE;
> 
> Here is my code that saves it.....
> Err iErr = DmWrite(vpszID, offsetof(DEBUGMESSAGE,szTime), &pszData->szTime, 
>StrLen(pszData->szTime));
> iErr = DmWrite(vpszID, offsetof(DEBUGMESSAGE,szDate), &pszData->szDate, 
>StrLen(pszData->szDate));
> iErr = DmWrite(vpszID, offsetof(DEBUGMESSAGE,pszMessage), pszData->pszMessage, 
>StrLen(pszData->pszMessage));
> 
> Here is my code that reads it...
> pDEBUGMESSAGE pszLocalData;           
> pszLocalData = (pDEBUGMESSAGE)MemHandleLock(hRecord);
> 
> Basically it doesnt' work. The first 2 vars, time and date are filled
> but the pszMessage isn't. Am I doing this correctly? I have found
> samples and followed them but it seems not to work. Are there any
> working examples?

You're dereferencing the string pointer on the way out (good, otherwise
you'd be saving the pointer, which wouldn't be valid when you got it back)
but not re-referencing it on the way in. Either you should read the string
out into some memory and point pszMessage to that memory, or use a struct
like

typedef struct tag_DebugMessage
{
      Char            szTime[timeStringLength];
      Char            szDate[dateStringLength];
      Char            pszMessage[1];
      
} DEBUGMESSAGE, *pDEBUGMESSAGE;

and allocate the string on the end of the struct so you don't need to
dereference/re-reference it. Also, you're going to want to either save the
length of the string somewhere or be sure to save the null terminator as
well.

Jake


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to