read binary file with fopen
Posted: Sun Sep 10, 2017 3:11 am
read binary file with fopen, already performed tests and does not work follow binary file
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://mail.hmgforum.com/
Code: Select all
#include "Fileio.ch"
#include "hmg.ch"
FUNCTION Main()
LOCAL cFile := "20161228.dtl"
LOCAL nHandle := fOpen(cFile, FO_READ + FO_COMPAT)
LOCAL nLen
LOCAL cContent
IF nHandle < 0
MsgBox("Error opening file!")
ELSE
fSeek(nHandle, 0, FS_SET)
nLen := HB_fSize(cFile)
//read all content of file
cContent := HB_fReadLen(nHandle, nLen)
MsgBox(Len(cContent))
//read 20 last bytes
fSeek(nHandle, -20, FS_END)
cContent := HB_fReadLen(nHandle, nLen)
MsgBox(Len(cContent))
fClose(nHandle)
ENDIF
RETURN NIL
KDJ wrote: ↑Sun Sep 10, 2017 12:22 pm jairpinho
This file can be read without any problem:Code: Select all
#include "Fileio.ch" #include "hmg.ch" FUNCTION Main() LOCAL cFile := "20161228.dtl" LOCAL nHandle := fOpen(cFile, FO_READ + FO_COMPAT) LOCAL nLen LOCAL cContent IF nHandle < 0 MsgBox("Error opening file!") ELSE fSeek(nHandle, 0, FS_SET) nLen := HB_fSize(cFile) //read all content of file cContent := HB_fReadLen(nHandle, nLen) MsgBox(Len(cContent)) //read 20 last bytes fSeek(nHandle, -20, FS_END) cContent := HB_fReadLen(nHandle, nLen) MsgBox(Len(cContent)) fClose(nHandle) ENDIF RETURN NIL