No mind readers here - without the code all we can do is guess. Either the master is closing the files, or the handles aren't being properly remembered and passed.
Lol, I like funny people. But please do not make jokes about sharing file handles across different scripts, or some people may believe you that it is possible.
Here I wrote you some code, I hope it helps you to read my mind. But keep in mind that I did not care about solution, just asked why.
testlib.mq4
#property library int handle = EMPTY; int init() { handle = FileOpen("test", FILE_WRITE|FILE_BIN); } int deinit() { FileClose(handle); // generates error } void dummy() { return; }
testindicator.mq.4
#property indicator_separate_window #import "testlib.ex4" void dummy(); #import int start() { dummy(); }
No joking. You said the second was a " the library file." There for the main must call functions in the second and can pass it parameters - Of course the handles can be shared.
As for your why, I didn't even know a init/deinit in a library is called directly. I assumed it had to be called by the main.
There's also the possibility that you can have two EAs but only one library, therefor storing local data in the library is incorrect.
Well. I do not want to argue with you, because I consider most of your posts rather aggressive. Just two things.
1. "Of course the handles can be shared"
MQL file handles are local, valid only within the code instance they were created. You cannot pass them to a library or another EA. If you say you can, you did not try.
2. "you can have two EAs but only one library, therefor storing local data in the library is incorrect.".
Not sure, what logic uses this implication. If you believe, that the same instance of library is shared by two EAs, then you are wrong. Every EA has its own instance of a library.
I have a library file, that implements a deinit() method.
The deinit() is correctly executed within the event of unload, right after the deinit() of the master script.
But, (unlike the deinit() of the master script) the file handles are already closed in the deinit() of the library file.
I do not need a solution, I just wonder, why the behaviour of deinit() is different here.
Bravo on your findings. It appears that you're correct in every instance. So the master deinit() closes your file handle. In all fairness, are you asking us why meta-quotes designed it this way?
If you're not asking us why meta-quotes designed it this way. Then the answer to your question is that the deinit() function closes the handle of the library which is called within its thread.
If you're asking why meta-quotes implemented such a confusing design of deinit() and Libraries then by all means please ask them for us.
Anyways, I like your responses and topics, I always learn something new.
-Peace-
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a library file, that implements a deinit() method.
The deinit() is correctly executed within the event of unload, right after the deinit() of the master script.
But, (unlike the deinit() of the master script) the file handles are already closed in the deinit() of the library file.
I do not need a solution, I just wonder, why the behaviour of deinit() is different here.