read binary file with fopen

Moderator: Rathinagiri

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

read binary file with fopen

Post by jairpinho » Sun Sep 10, 2017 3:11 am

read binary file with fopen, already performed tests and does not work follow binary file
20161228.zip
file *.dtl
(3.39 KiB) Downloaded 17 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

KDJ
Posts: 164
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 148 times

Post by KDJ » 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

User avatar
jairpinho
Posts: 194
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 1 time
Contact:

Post by jairpinho » Sun Sep 10, 2017 6:49 pm

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

User avatar
serge_girard
Posts: 1805
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 261 times
Been thanked: 60 times
Contact:

Post by serge_girard » Mon Sep 11, 2017 7:29 am

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

User avatar
BeGeS
Posts: 81
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 15 times
Been thanked: 13 times

Post by BeGeS » Mon Sep 11, 2017 2:09 pm

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: 1805
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 261 times
Been thanked: 60 times
Contact:

Post by serge_girard » Mon Sep 11, 2017 3:37 pm

Absolutely right !

Browsing works with Free Hex Editor Neo.

Post Reply