New article File Operations via WinAPI has been published:
Environment MQL4 is based on the conception of safe "sandbox": reading and saving files using the language are allowed in some predefined folders only. This protects the user of MetaTrader 4 from the potential danger of damaging important data on the HDD. However, it is sometimes necessary to leave that safe area. This article is devoted to the problem of how to do it easily and correctly.
MQL4 is designed in such a way that even incorrectly written programs
are unable to mistakenly delete data from the hard disk. The functions
used for file reading and writing operations can work in the following directories only (quote):
Author: MetaQuotes Software Corp.
Thank you Rashid for a well presented article.
Annotated text with colors and vids are a well received addition in the issue of learning imho.
My understanding is heightened by your implementation of these tools.
The final "Let's modify function start() to check the new features:" is very concise and elegant ;)
I always have a bad feeling concerning file interfaces - although I use them more or less without trouble.
But isn't there any way to pass data from one EA to another (or some other app) directly through the RAM? Like with some sort of RPC/RMI or whatever!?
Your WinAPI file operations are very useful. Thank you so much. I incorporated your code into my Correlation indicator (which I will share when completed). However, your ReadFile() function seems to return a string from a text file dropping all the non-printable characters. In my application I NEED the non-printable characters "/r/n" to signal end of line. Because my indicator requires the user input (currency pair) be validated against the broker symbols. My set file does not use ";" delimiter; it is only one column of symbols in a plain text file. I actually tried to use the standard FileOpen() in FILE_CSV mode but it only allows the use of ';' as the delimiter (see attached).
Any help is much appreciated.
How can I use the FileWrite function for update a whole file? So, I would like to delete the all characters of the previous content of the file.
There is one way - I think. I could delete the file before the write.
int _lcreat (string path, int attrib);
This does not work on MT4 build 600, 604.
Please help! Thanks!
why using _lopen and friends that are still there for backward compatibility and msdn doesnt even document them anymore? you can use CreateFile from kernel32 or fopen from msvcrt..
also you should check if return value is -1 ( HFILE_ERROR ) which is the value if the function fails, checking if is less than 0 it's pretty bad since on error the value is -1 and not less than 0