DOCUMENT:Q67795 08-OCT-1999 [utilities] TITLE :EXE File Checksum Incorrect If LINK /CO or /E Option Used PRODUCT :Microsoft Programming Utilities PROD/VER:: OPER/SYS: KEYWORDS:kb16bitonly ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft LINK for MS-DOS - Microsoft LINK for OS/2 ------------------------------------------------------------------------------- SUMMARY ======= According to "The MS-DOS Encyclopedia," an MS-DOS .EXE file contains a checksum value in its .EXE file header. This checksum value should make the sum of all words in the .EXE file equal FFFFh. However, if the LINK command line specifies the /CODEVIEW or /EXEPACK options, LINK does not calculate the checksum correctly. Because current versions of MS-DOS ignore this checksum, this does not cause any noticeable problems. Note that Microsoft LINK versions 5.3 and later do not compute a checksum value. The reserved bytes in the .EXE header are set to zero. MORE INFORMATION ================ The following code example calculates the checksum for a specified MS-DOS executable file. Sample Code ----------- #include #include main (int argc, char * argv[]) { FILE * fp; unsigned int nxt = 0, sum = 0; unsigned char bl, bh; if (argc != 2) exit(-1); if ((fp = fopen(argv[1], "rb")) == NULL) exit(-1); while (!feof(fp)) { bl = fgetc(fp); if (!feof(fp)) bh = fgetc(fp); else { bl = 0; bh = 0; } sum = sum + nxt; nxt = (unsigned int)bh * 256U + (unsigned int)bl; } nxt &= 0xFF; sum += nxt; printf("sum = %X\n", sum); } Additional query words: kbinf 3.x 4.0x 4.10 5.0x 5.10 5.13 5.1x LinkIss ====================================================================== Keywords : kb16bitonly Technology : kbAudDeveloper kbZNotKeyword3 kbLINKSearch Version : : ============================================================================= 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. Copyright Microsoft Corporation 1999.