Reading and writing files anywhere on disk using CreateFileA() etc.

Back to topics list To post a new topic, please log in or register
avatar
1332
jjc 2009.07.20 21:49
 

There are frequent questions in this forum (e.g. 'Difficulty using FileReadString on file opened outside /experts/files') about reading and writing files anywhere on the hard disk, but there only seems to be one published library for doing so, and it's fairly limited: 'File Operations without Limitations'


The attached include-file uses the CreateFileA(), ReadFile() etc family of Windows API functions rather than _lcreat(), lread() etc. Differences/improvements from https://www.mql5.com/en/code/8314 are as follows:


  • Provides a read function which uses a 200-byte buffer, whereas https://www.mql5.com/en/code/8314 seems to read the file 1 byte at a time.
  • Provides a ReadLineFromFile() function which can be used to read CRLF-terminated (or pipe-terminated etc) lines, rather than having to read an entire file into memory and then split it.
  • Provides functions for reading and writing an array of doubles.
  • Provides a wrapper function for opening a new file in append mode.
  • Provides wrapper functions with parameters for opening files in shared mode.
  • The _lcreat() functions etc used in https://www.mql5.com/en/code/8314 are deprecated by Microsoft, and ideally shouldn't be used.

Use at your own peril; not fully tested etc...

Attached files:
  winfile.mqh  (24.62 KB)
 
avatar
1332
jjc 2009.07.20 21:50 #
 
jjc:

The attached include-file [...]

...and the attached file is a test script for the above include-file.

Attached files:
  testwinfile_2.mq4  (5.20 KB)
avatar
865
fbj 2009.07.20 22:53 #
 

jjc - you're Da Man!

Presently, I do not have requirement but will download and save 'for that rainy day' and the learning about api i/f is always of interest too!

Many thank you's offered :O)

.

edit: once again having dl'd into ed, I'm struck by your code. Has always proved to be a pleasure to read. Formatting, comments and concise too.

Heaven knows is bad enough coding let alone maintenance - which in my case means after first clean compile, yet your src is agreeable and this is massively important and severely underrated by many...

are you also a 'gun for hire'?

I ask cuz my distinct brain dead feelings seem more obvious these days... like for the last 10yrs :o)

a pm?

avatar
1332
jjc 2009.07.21 02:58 #
 
fbj:

jjc - you're Da Man!

Er, no. Leaving the code aside, there are at least two "bugs" just in the comments. The notes on OpenExistingFileForReading() have a nonsensical reference to appending and overwriting, caused by pasting the text from the previous function. And the notes in the test script refer to writing CRLF-terminated lines despite the fact that I changed the code to provide a more useful example of pipe-terminated blocks.


are you also a 'gun for hire'?

Up to a point. See www.mtintelligence.com/about.aspx


avatar
57
Dohung 2014.02.13 02:57 #
 

Hi,

As MT4 upgrate to build 600, I can not use _lcreat(), lread() etc.

Please support, Thanks!

avatar
3134
qjol 2014.02.13 03:44 #
 

according to MSDN - Microsoft:

This function is provided for compatibility with 16-bit versions of Windows. New applications should use the CreateFile function.

B.T.W. in the new MT4 u have to use CreateFileW instead of CreateFileA

avatar
14167
RaptorUK 2014.02.13 10:42 #
 
Dohung:

Hi,

As MT4 upgrate to build 600, I can not use _lcreat(), lread() etc.

Please support, Thanks!

Why are you replying to a 4.5 year old thread ?

avatar
10
appleparty 2015.01.13 06:39 #
 

the newest change is  CreateFileA()---CreateFileW()    DeleteFileA()---DeleteFileW()    delete  StringSplit() function (the new mt4 600+  Contains this function)    

and it's good to use from  Excel2txt2mql   or mql2txt2mql 

and  It should be noted that  the "xxx.txt" must be  unicode encoding

 

Back to topics list  

To add comments, please log in or register