You are probably overwriting the chunk of memory - most of the time this is a StrLen(str) vs. StrLen(str)+1 type of error when you allocate the chunk (the later being the correct amount of memory).
K -----Original Message----- From: Frank Panetta [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 12:41 AM To: Palm Developer Forum Subject: DataMgr.c, Line:7386, DmWrite:DmWriteCheck failed Hi, I've developed an app for the spt1800 and I'm curently trying to sort out the bugs. My main issue at the moment is that I get is that I get a "DataMgr.c, Line:7386, DmWrite:DmWriteCheck failed" error after scanning a barcode. It dosen't happen all the time but regular enough to be a problem. I've attached a sample of my code. /*********************************************************************** * * FUNCTION: SetFieldText * * DESCRIPTION:Perform all necessary actions to set a Field control's * text and redraw, if necesary. Allocates a text handle. * * * PARAMETERS: nFieldID(in) - The resource ID of the field. * pSrcText(in) - The text to copy into field. * nMaxSize(in) - Max size that the field can grow. * bRedraw(in) - Should the text be redrawn now? * * RETURNED: None * ***********************************************************************/ void SetFieldText( UInt16 nFieldID, const Char *pSrcText, Int16 nMaxSize, Boolean bRedraw ) { MemHandle hFieldText; Char * pFieldText; FieldPtr pField; pField = (FieldPtr)GetObjectPtr( nFieldID ); if( !pField ) return; hFieldText = FldGetTextHandle( pField ); if( !hFieldText ) hFieldText = MemHandleNew( nMaxSize ); // If already allocated, make sure it can handle nMaxSize already. // If not, realloc that buffer else { UInt32 curSize = MemHandleSize( hFieldText ); if( curSize < nMaxSize ) MemHandleResize(hFieldText, nMaxSize ) ; } if( hFieldText ) { Int16 len = StrLen(pSrcText); pFieldText = (Char * )MemHandleLock( hFieldText ); if (len > nMaxSize) { StrNCopy( pFieldText, pSrcText, nMaxSize-1); pFieldText[nMaxSize-1] = '\0'; } else StrCopy( pFieldText, pSrcText ); MemHandleUnlock( hFieldText ); FldSetTextHandle( pField, (MemHandle)hFieldText ); FldSetTextAllocatedSize( pField, nMaxSize ); FldSetMaxChars( pField, nMaxSize-1); FldRecalculateField( pField, true ); if( bRedraw ) FldDrawField( pField ); } } /* turn a5 warning off to prevent it being set off by C++ * static initializer code generation */ #pragma warn_a5_access reset /*********************************************************************** * * FUNCTION: OnDecoderData * * DESCRIPTION: Called when the app receives a scanDecodeEvent, which * signals that a decode operation has been completed. * Calls the Scan Manager function "ScanGetDecodedData" * to get the scan data and barcode type from the last * scan. Fills in the controls on the main form that * display this information. * * RETURNED: True if the event is handled, false otherwise. * ***********************************************************************/ Boolean OnDecoderData(FormType * frmP) { MESSAGE decodeDataMsg; Int16 status; MemHandle hExtendedData; UInt8 *pExtendedData; Int16 extendedDataType; EraseWinChars(); if (extend) { hExtendedData = MemHandleNew( extendedDataLength ); pExtendedData = (UInt8 *)MemHandleLock( hExtendedData ); status = ScanGetExtendedDecodedData(extendedDataLength, &extendedDataType, pExtendedData); } else { status = ScanGetDecodedData( &decodeDataMsg ); extendedDataType = decodeDataMsg.type; extendedDataLength = decodeDataMsg.length; hExtendedData = MemHandleNew(extendedDataLength+1); pExtendedData = (UInt8 *)MemHandleLock( hExtendedData ); pExtendedData[extendedDataLength] = '\0'; MemMove( &pExtendedData[0], &decodeDataMsg.data[0], extendedDataLength+1 ); } if( status == STATUS_OK ) // if we successfully got the decode data from the API... { FieldPtr pField; UInt16 nFieldID; nFieldID = FrmGetObjectId(frmP,FrmGetFocus(frmP)); // Check to see if this scan was a "No Data Read" (indicated by type of zero). if( extendedDataType == 0) { SetFieldText( nFieldID , "No Scan", 8, true ); } else { // Place the barcode data into the field and display /* Set up data display field to display the memory */ pField = (FieldPtr)GetObjectPtr(nFieldID); FldDelete(pField, 0, FldGetTextLength(pField)); // clear out old data if (extendedDataLength > FldGetMaxChars(pField)) FldSetMaxChars (pField, extendedDataLength); FldEraseField(pField); // hide field so we don't // see the data scroll in if(nFieldID == MainQuantityField || nFieldID == MainQuantityField){ UInt16 index; if(extendedDataLength > 6){ FrmCustomAlert(TooLongAlert,"Quantity","",""); if(nFieldID == MainPartNoField){ SetFieldText(MainQuantityField,"1",extendedDataLength,true); } if(nFieldID == StocktakePartNoField){ SetFieldText(StocktakeQuantityField,"1",extendedDataLength,true); } FldDrawField(pField); MemHandleUnlock(hExtendedData); MemHandleFree(hExtendedData); return(0); } for ( index = 0; index < extendedDataLength; index++){ if(!TxtCharIsDigit(pExtendedData[index])){ FrmCustomAlert(NumbersOnlyAlert,"Quantity","",""); if(nFieldID == MainPartNoField){ SetFieldText(MainQuantityField,"1",extendedDataLength,true); } if(nFieldID == StocktakePartNoField){ SetFieldText(StocktakeQuantityField,"1",extendedDataLength,true); } FldDrawField(pField); MemHandleUnlock(hExtendedData); MemHandleFree(hExtendedData); return(0); } } SetFieldText( nFieldID ,(Char *)&pExtendedData[0], extendedDataLength, true ); } else{ SetFieldText( nFieldID ,(Char *)&pExtendedData[0], extendedDataLength, true ); } if(nFieldID == MainPartNoField){ SetFieldText(MainQuantityField,"1",extendedDataLength,true); GetPartDesc(MainPartNoField); } if(nFieldID == StocktakePartNoField){ SetFieldText(StocktakeQuantityField,"1",extendedDataLength,true); GetPartDesc(StocktakePartNoField); } } } MemHandleUnlock(hExtendedData); MemHandleFree(hExtendedData); return(0); } Thanks Frank -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ ------------------------------------------ The information in this transmittal and any attachments is privileged and confidential and is intended only for the recipient(s) listed above. You are hereby notified that any unauthorized distribution or copying of this transmittal or its attachments is prohibited. If you have received this transmittal in error, please notify Invivodata immediately at (831) 438-9550. ------------------------------------------ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
