Once you close the file, the handle will be invalid
no zuegg, while the expert tries to write something else the file is still open.
here's a piece of the code:
the expert:
int h=MyFileOpen (title, FILE_WRITE); string s0= "..."; FileWrite(h,s0); FileClose(h);
the external function:
int MyFileOpen (string title, int mod) { int handle; string s, fname; //-----> fname = title+".txt"; handle = FileOpen(fname, mod); if(handle<1) { Print("File not found, the last error is: ", GetLastError()); return(handle); } FileWrite(handle,"something"); return (handle); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi everyone,
i have experienced a problem with a file handle passed by a function resident in an external library (.ex4).
Basically i was creating a function that opens a text file (to write all the initial standard text lines) and then passes back its handle to the expert for the prosecution (write something more ... and then close the file).
Of course the expert "receives" the handle of the opened file correctly - i made it print it out - but when "he" tries to write down something more and then close the file it will report "handle 1 does not exist in filewrite" / "handle 1 does not exist in fileclose".
i'm sure that "1" its the right file handle, since it's the only one open file and i made it print it out both from the library and from the expert.
Also, if I open the same file from the same expert instead from a library, everything will work fine.
anybody can help to understand this behaviour?