read binary file with fopen
Moderator: Rathinagiri
- jairpinho
- Posts: 221
- Joined: Mon Jul 18, 2011 5:36 pm
- Location: Rio Grande do Sul - Brasil
- Been thanked: 2 times
- Contact:
read binary file with fopen
read binary file with fopen, already performed tests and does not work follow binary file
jairpinho
This file can be read without any problem:
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
- jairpinho
- Posts: 221
- Joined: Mon Jul 18, 2011 5:36 pm
- Location: Rio Grande do Sul - Brasil
- Been thanked: 2 times
- Contact:
KDJ wrote: ↑Sun Sep 10, 2017 12:22 pmjairpinho
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
Hello KDJ you are reading the file size this is not an error, it will only give an error when trying to read the contents of the file that would be what I need to follow, an example of what is inside the file, I need to import this into a grid
- serge_girard
- Posts: 2030
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Has thanked: 380 times
- Been thanked: 87 times
- Contact:
Jair,
IMO: better take a EDITBOX to display content.
For a GRID you will need to create several lines (say 80char), divide cContent in chuncks of 80chars and put them in a GRID.
Serge
IMO: better take a EDITBOX to display content.
For a GRID you will need to create several lines (say 80char), divide cContent in chuncks of 80chars and put them in a GRID.
Serge
- BeGeS
- Posts: 110
- Joined: Fri Jul 14, 2017 10:45 am
- DBs Used: DBF
- Location: La Mancha, Spain
- Has thanked: 29 times
- Been thanked: 21 times
Serge,
This is a .DTL file.
I'm afraid that with EDITBOX you will not get anything, neither with FREADSTR() or similar low-level functions.
It would be necessary a tool that would make the contents of the file something readable.
This is a .DTL file.
I'm afraid that with EDITBOX you will not get anything, neither with FREADSTR() or similar low-level functions.
It would be necessary a tool that would make the contents of the file something readable.
I get by with a little help from my friends
- serge_girard
- Posts: 2030
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Has thanked: 380 times
- Been thanked: 87 times
- Contact:
- jairpinho
- Posts: 221
- Joined: Mon Jul 18, 2011 5:36 pm
- Location: Rio Grande do Sul - Brasil
- Been thanked: 2 times
- Contact:
Hello, I found the dtl files are data files, I'm trying to connect via odbs but without success, so I found the lib site need help to convert the mak file
http://dtemplatelib.sourceforge.net/index.htm
http://dtemplatelib.sourceforge.net/index.htm