How to Calculate the Checksum Byte of a General Field

Last reviewed: June 27, 1995
Article ID: Q129534
The information in this article applies to:
  • Microsoft FoxPro for Windows, version 2.6a

SUMMARY

When a bitmap is appended to a general field, the actual information of the general field is stored in the associated .FPT file. The .FPT file holds the bitmap information followed by four bytes. The first of these four bytes is a checksum byte. The next three bytes are: AD 05 FE in hex.

This article lists the C code that writes the checksum byte to enable programmers to write their own General fields manually if so desired.

MORE INFORMATION

The checksum byte is calculated by FoxPro by using the following C code:

static unsigned char ObjectCheckSum = 0;

 //+-----------------------------------------------------------------------
 //
 //  Function: CalcCkSum, private
 //
 //  Synopsis:  Calculates the checksum for a general field.
 //
 //  Arguments: [ptr] -- pointer to data to calculate checksum on.
 //             [cb] -- number of bytes in the buffer.
 //
 //  Modifies:  ObjectCheckSum
 //
 //------------------------------------------------------------------------

 LOCAL void CalcCkSum(void *ptr, long cb)
 {
    long cktemp = 0;
    long cl = cb >> 2;
    long *lp = (long *) ptr;
    TEXT *cp;

    while(cl--)
       cktemp ^= *lp++;
       cl = cb & 3;  // Any remainder?
       cp = (TEXT *)lp;
    while(cl--)
       cktemp ^= *cp++;

    ObjectCheckSum ^= cktemp;
    ObjectCheckSum ^= cktemp >> 8;
    ObjectCheckSum ^= cktemp >> 16;
    ObjectCheckSum ^= cktemp >> 24;
  }


Additional reference words: FoxWin 2.60a
KBCategory: kbprg kbcode
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.