MORE INFORMATION
The first step in this process is to get the executable header
information. This is documented in the "Microsoft MS-DOS Programmers
Reference" (published by Microsoft Press). The following is the format
of an executable header as defined by a QuickBasic program:
TYPE EXEHEADER
exSignature AS INTEGER
exExtraBytes AS INTEGER 'Number of bytes in last page
exPages AS INTEGER 'Number of whole and part pages
exRelocItems AS INTEGER
exHeaderSize AS INTEGER
exMinAlloc AS INTEGER
exMaxAlloc AS INTEGER
exInitSS AS INTEGER
exInitSP AS INTEGER
exCheckSum AS INTEGER
exInitIP AS INTEGER
exInitCS AS INTEGER
exRelocTable AS INTEGER
exOverlay AS INTEGER
END TYPE
The two fields exExtraBytes and exPages can be used to compute the
size of the image area of the executable, and thus the beginning of
the data area.
The following is a small program that will create a data file
containing a graphics image created with the PRINT and LINE statements
in Basic:
SCREEN 12
COLOR 1 'Select Blue for the color
DIM box%(1 TO 1792) 'Dimension an array big enough for the GET
'statement
LOCATE 2, 2 'Locate the "Hello" text
PRINT "Hello";
LINE (1, 15)-(55, 30), , B 'Draw a box
GET (1, 1)-(55, 30), box% 'Get the box
OPEN "DATAFILE" FOR BINARY AS #1
FOR i% = 1 TO 1792
PUT #1, , box%(i%) 'Save image to disk
NEXT i%
CLOSE #1
END
The next example should be compiled and have the data file from the
previous program appended on the end of the executable. Type in the
following program, and save it with the name TEST.BAS:
TYPE EXEHEADER
exSignature AS INTEGER
exExtraBytes AS INTEGER 'Number of bytes in last page
exPages AS INTEGER 'Number of whole and part pages
exRelocItems AS INTEGER
exHeaderSize AS INTEGER
exMinAlloc AS INTEGER
exMaxAlloc AS INTEGER
exInitSS AS INTEGER
exInitSP AS INTEGER
exCheckSum AS INTEGER
exInitIP AS INTEGER
exInitCS AS INTEGER
exRelocTable AS INTEGER
exOverlay AS INTEGER
END TYPE
DIM exeheadblock AS EXEHEADER
OPEN "test.exe" FOR BINARY AS #1
GET #1, , exeheadblock 'This puts the executable header in
'to the structure exeheadblock
CLS
SCREEN 12
DIM box%(1 TO 1792)
IF exeheadblock.exPages MOD 512 <> 0 THEN
size = exeheadblock.exPages * 512& -(512&-exeheadblock.exExtraBytes)
ELSE 'If no partial pages then execute the else statement
size = exeheadblock.exPages * 512&
END IF
GET #1, size + 1, box%(1) 'Read each element of the array
FOR i% = 2 TO 1792
GET #1, , box%(i%)
NEXT i%
CLOSE #1
PUT (100, 100), box% 'Put the graphics image to the screen
SLEEP
END
After compiling this program into TEST.EXE, use the MS-DOS TYPE
command to append the data file to the end of the executable as
follows:
type datafile >> test.exe
Run the program and you will see the image that was created in first
program displayed in the second program.
For more information about the format used by the graphics PUT and GET
statements to store images into an array, query on the following
words in the Microsoft Knowledge Base:
get and put and array and graphics and pixels and image