Page 1 of 1

read binary file with fopen

Posted: Sun Sep 10, 2017 3:11 am
by jairpinho
read binary file with fopen, already performed tests and does not work follow binary file
20161228.zip
file *.dtl
(3.39 KiB) Downloaded 278 times

Re: read binary file with fopen

Posted: Sun Sep 10, 2017 12:22 pm
by KDJ
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

Re: read binary file with fopen

Posted: Sun Sep 10, 2017 6:49 pm
by jairpinho
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

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
dados arquivo.gif
dados arquivo.gif (59.48 KiB) Viewed 4830 times

Re: read binary file with fopen

Posted: Mon Sep 11, 2017 7:29 am
by serge_girard
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

Re: read binary file with fopen

Posted: Mon Sep 11, 2017 2:09 pm
by BeGeS
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.

Re: read binary file with fopen

Posted: Mon Sep 11, 2017 3:37 pm
by serge_girard
Absolutely right !

Browsing works with Free Hex Editor Neo.

Re: read binary file with fopen

Posted: Sat Jan 06, 2018 2:32 am
by jairpinho
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
DTLbcb5.zip
(1.27 KiB) Downloaded 239 times