Microsoft KB Archive/67795

= EXE File Checksum Incorrect If LINK /CO or /E Option Used =

Article ID: 67795

Article Last Modified on 10/23/2003

-

APPLIES TO


 * Microsoft LINK for MS-DOS
 * Microsoft LINK for OS/2

-



This article was previously published under Q67795



SUMMARY
According to &quot;The MS-DOS Encyclopedia,&quot; 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

 * 1) include 
 * 2) 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], &quot;rb&quot;)) == 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(&quot;sum = %X\n&quot;, sum);

}

Additional query words: kbinf 3.x 4.0x 4.10 5.0x 5.10 5.13 5.1x LinkIss

Keywords: kb16bitonly KB67795

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.