[ Home | Optimize | Current | Project | Tools | Made in France | F.A.Q | Forums | Links | Sources Codes ]

1 - READING FROM A FILE

For reading from a file, that supposes that the file has been opend in GENERIC_READ mode.

What kind of problem can you meet when reading :

The file handle is not valid,
The file has not been open with the GENERIC_READ mode,
Part of the file is locked,
The file is empty,
You have passed the end of the file.

Here is an example of what such a function could be :

ReadFromThisFile  PROC  USES EBX EDI ESI,__hFile:HANDLE,__lpBuffer:LPBYTE,__dwDataSize:DWord
                  LOCAL  _dwNbOfBytesRead:DWord

                  mov    edi,__hFile
                  mov    esi,__lpBuffer
                  mov    ebx,__dwDataSize

                  test   edi,edi                  ; The file handle is NULL ?
                  jz     @Error

                  test   esi,esi                  ; The file buffer is NULL ?
                  jz     @Error

                  test   ebx,ebx                  ; Data size to write is 0 ?
                  jz     @Error

                  INVOKE ReadFile,edi,esi,__dwDataSize,ADDR _dwNbOfBytesRead,NULL

                  test   eax,eax                  ; Function failed
                  jz     @Exit

                  cmp    _dwNbOfBytesRead,0       ; EOF ?
                  je     @Error

                  cmp    ebx,_dwNbOfBytesRead     ; Datas read to disk ?
                  je     @Exit                    ; Yes

@Error :          xor    eax,eax

@Exit :

                  test   eax,eax
                  ret
ReadFromThisFile  ENDP

This function returns TRUE if the read operation returns successfully.
The function return FALSE if an error occured or if the file handle is NULL or the file buffer is NULL or the datas size to read is 0.

At the end of the function the ZERO flag is set if an error occured.

INVOKE ReadFromThisFile,_FileHandle,ADDR _szBuffer,SIZEOF _szBuffer
jz     @Error

<Return>

 

[ Home | Optimize | Current | Project | Tools | Made in France | F.A.Q | Forums | Links | Sources Codes ]