FILE *pf = fopen("experts\\files\\example.txt","r");
everytime the message shows the dll can't open file, i checked the directory, the example.txt it is there, but the dll can't open it.
i think must be the fileclosed havn't closed it in time.
how to fix this?? thanks for any advices.
Firstly, I'd try calling the Windows API function GetLastError() after the fopen(). That should tell you exactly what the file problem is - because fopen() is basically a wrapper around CreateFile(), and that sets the Win32 API last error.
However, my guess is that "experts\\files\\example.txt" is wrong. When I try calling a DLL from MetaTrader the current directory is set to My Documents, not \Program Files\<metatrader instance>. I think you'll need to pass the location of MetaTrader into the DLL, using MQL's TerminalPath() function, and then build a full file path rather than a relative one.
Firstly, I'd try calling the Windows API function GetLastError() after the fopen(). That should tell you exactly what the file problem is - because fopen() is basically a wrapper around CreateFile(), and that sets the Win32 API last error.
However, my guess is that "experts\\files\\example.txt" is wrong. When I try calling a DLL from MetaTrader the current directory is set to My Documents, not \Program Files\<metatrader instance>. I think you'll need to pass the location of MetaTrader into the DLL, using MQL's TerminalPath() function, and then build a full file path rather than a relative one.
thank you .guys. especially jjc.
your advice is good, i will check lasterror. but the path problem, i have tested too. if use dll write a file, the path is program files\metatrader instance. in my code is
\\experts\\files\\example.txt. i have tested that too, if i don't call open file from ea, dll call always works fine, so must be the file function problem in ea .
thank you very much.
stradz, c# dll is not a really dll, it is depend on .net framework. so if you write dll for mt4 use, you must write it with c++ or c, some one also use delphi too. hope this can help you.
thank you .guys. especially jjc.
your advice is good, i will check lasterror. but the path problem, i have tested too. if use dll write a file, the path is program files\metatrader instance. in my code is
\\experts\\files\\example.txt. i have tested that too, if i don't call open file from ea, dll call always works fine, so must be the file function problem in ea .
thank you very much.
stradz, c# dll is not a really dll, it is depend on .net framework. so if you write dll for mt4 use, you must write it with c++ or c, some one also use delphi too. hope this can help you.
yes, Delphi is great :-) in my personal opinion of course!
- 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 met a problem, at same condition, some time it comes, and some time it didn't come.
here is the code.
i use ea create this sample first.
i create a dll file, which has a function which read some data form a sample.txt.
code like this
everytime the message shows the dll can't open file, i checked the directory, the example.txt it is there, but the dll can't open it.
i think must be the fileclosed havn't closed it in time.
how to fix this?? thanks for any advices.