BCX Console Demonstration Program s77.bas

 DIM FileSize
 DIM Junk
 
 IF COMMAND$ = "" THEN
   PRINT "Usage: S77 filename"
   END
 END IF
 
 DIM Buffer$ * LOF(COMMAND$) + 1
 
 FileSize = LoadFile(COMMAND$, Buffer$)
 
 COLOR 3, 0 : PRINT "LoadFile loaded", FileSize, " bytes into Buffer$"
 COLOR 7, 0 : INPUT "Press Enter to display contents of Buffer$", Junk
 CLS
 
 PRINT Buffer$
 
 FREE Buffer$
 
 FUNCTION LoadFile(Fname$, Buffer$) AS DWORD
   ' ------------------------------------------------------ 
   ' Assumes Fname$ is a valid FileName to an existing file 
   ' Assumes Buffer$ is large enough to hold entire file 
   ' ------------------------------------------------------- 
   DIM Read AS DWORD
   DIM H    AS HANDLE
   DIM Fsize
   Fsize = LOF (Fname$)
   H = CreateFile(Fname$, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0)
   IF H THEN
     ReadFile(H, Buffer$, Fsize, &Read, NULL)
     CloseHandle(H)
   END IF
   FUNCTION = Read
 END FUNCTION