read binary file with fopen

Moderator: Rathinagiri

Post Reply
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

read binary file with fopen

Post 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 277 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: read binary file with fopen

Post 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
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: read binary file with fopen

Post 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 4825 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: read binary file with fopen

Post 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
There's nothing you can do that can't be done...
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: read binary file with fopen

Post 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.
I get by with a little help from my friends
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: read binary file with fopen

Post by serge_girard »

Absolutely right !

Browsing works with Free Hex Editor Neo.
There's nothing you can do that can't be done...
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: read binary file with fopen

Post 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
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
Post Reply