Download MetaTrader 5

EA can't work properly due to WinAPI functions failing to load.

To add comments, please log in or register
Have you made a screenshot in MetaTrader? Share it with friends!
BigFisherman
125
BigFisherman 2014.03.02 22:52 

Hi All, anyone had this problem with lots of WinAPI functions failing to load in their terminal? I'm on Win 7 64 bit OS, MT4 build 610. EA had some functions failing because lots of WinAPI fail to load when I look into the Dependencies of EA dialog. My windows is always updated. Any idea what's going on? Here's some screenshots of my EA Dialog showing the dependencies failing to load.

WinAPI failure1

WinAPI failure2

Thanks in advance.

Alain Verleyen
Moderator
30742
Alain Verleyen 2014.03.03 00:10  
BigFisherman:

Hi All, anyone had this problem with lots of WinAPI functions failing to load in their terminal? I'm on Win 7 64 bit OS, MT4 build 610. EA had some functions failing because lots of WinAPI fail to load when I look into the Dependencies of EA dialog. My windows is always updated. Any idea what's going on? Here's some screenshots of my EA Dialog showing the dependencies failing to load.

Thanks in advance.

Are you sure you declare these functions correctly in your EA ?

For example I see you are using ResolveLocaleName, but I can't see parameters. See MSDN documentation.

BigFisherman
125
BigFisherman 2014.03.03 00:24  

I didn't call ResolveLocalName in my EA, it's part of WinFile.mqh.

I notice this DLL problem wasn't consistent in all build 610. I had another user account within the same PC installed with MT4 build 610, but it didn't have this DLL problem.. Was fine last week before the market close. I suspect something to do with my windows setting.

Alain Verleyen
Moderator
30742
Alain Verleyen 2014.03.03 00:27  
BigFisherman:

I didn't call ResolveLocalName in my EA, it's part of WinFile.mqh.

I notice this DLL problem wasn't consistent in all build 610. I had another user account within the same PC installed with MT4 build 610, but it didn't have this DLL problem.. Was fine last week before the market close. I suspect something to do with my windows setting.

What'is WinFile.mqh ?

Current build is 613.
BigFisherman
125
BigFisherman 2014.03.03 03:44  
angevoyageur:

What'is WinFile.mqh ?

Current build is 613.

It's a library to call some kernel32.dll functions developed by JJC & shared generously for the public. https://www.mql5.com/en/forum/118999

However for the recent mql4 upgrade, I've modified some of the codes to allow reading & writing Unicode string. I managed to get it to work for my EA until this morning when market reopens, with build 610.

As an update, the loading DLL problem disappears by itself "magically" after few hours without me changing anything yet. But now I had another related problem with reading Unicode strings written to a csv file. Updated MT4 to latest 613 but still having this problem. Here's the cutout code modified from JJC's original WinFile.mqh to read line of text. Writing text to file works correctly, but now I can't get it to read strings anymore. Any idea what's wrong with the modified code? Much thanks!

// (UPDATED FOR UNICODE STRING)
string ReadLineFromFile(int FileHandle, string Terminator = "\r\n")
{
   // Holds the line which is eventually returned to the caller 
   string Line = "";

   // Keep track of the file pointer before we start doing any reading 
   int InitialFilePointer = SetFilePointer(FileHandle, 0, 0, FILE_CURRENT);
   
   // Keep reading from the file until we get the end of the line, or the end of the file 
   bool bContinueRead = true;
   while (bContinueRead)
   {
      // Receives the number of bytes read from the file. Note that MQL can only pass 
      // arrays as by-reference parameters to DLLs
      int BytesRead[1] = {0};

      // 200-byte buffer...
      string ReadBuffer = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
      int BufferLength = StringLen(ReadBuffer) * 2;      // 2 * UNICODE STRINGLENGTH = BYTES OF UNICODE STRING

      // Do a read of up to 200 bytes 
      ReadFile(FileHandle, MulDiv(ReadBuffer, 1, 1), BufferLength, BytesRead, 0);

      // Check whether any data has been read...
      if (BytesRead[0] != 0)
      {
         // Add the new data to the line we've built so far
         Line = StringConcatenate(Line, StringSubstr(ReadBuffer, 0, BytesRead[0]));

         // Does the line now contain the specified terminator?
         int pFindTerminator = StringFind(Line, Terminator);
         if (pFindTerminator != -1)
         {
            // The line does contain the specified terminator. Remove it from the data we're 
            // going to pass back to the caller
            Line = StringSubstr(Line, 0, pFindTerminator);
            
            // We've almost certainly read too much data - i.e. the latest 200 byte block 
            // intrudes into the next line. Need to adjust the file pointer to the start
            // of the next line. This must be the file pointer before we started reading, plus
            // the length of the line we've read, plus the length of the terminator 
            SetFilePointer(FileHandle, InitialFilePointer + ((StringLen(Line) + StringLen(Terminator))*2), 0, FILE_BEGIN);
         
            // Stop reading 
            bContinueRead = false;
         } else {
            // The line read so far does not yet contain the specified terminator 
            bContinueRead = true;
         }
         
      } else {
         // Either at the end of the file, or the file handle is not valid for reading 
         bContinueRead = false;
      }
   }

   return (Line);
}
BigFisherman
125
BigFisherman 2014.03.03 08:33  

Ok, managed to solve it after many hours of frustrations. For the benefit of anyone who may face the same problem, it's not the problem of my modified code attached above; the code works fine. I do not have the exact explanation to what has caused this DLL / kernel32.dll readfile problem, but here's a rough guide on what I did the entire day to solve this:

1) Restore OS (using windows restore point) to a few days back when MT4 is still functioning properly.

2) EA will most likely still not work after restore for dunno what reason. Open MT4 terminal & go into metaeditor, close MT4 terminal with only metaeditor open. Re-compile EA, re-open MT4 terminal & run through debug mode once, that kinds of "flush" the EA to make it work the way it should (sounds strange but the debug step is necessary to make my EA work, simply overwriting the recompiled EA doesn't work & it kept failing to read strings from csv file). That's all it take to return my EA back to normal. Btw, my restored MT4 is still build 610, it should works the same for build 613.

Hope that helps someone.

JC
1456
JC 2014.03.03 17:21  
BigFisherman:

It's a library to call some kernel32.dll functions developed by JJC & shared generously for the public. https://www.mql5.com/en/forum/118999

Try the attached version which is updated for use with v600. I haven't fully re-tested it, but it looks as though it works.
Files:
BigFisherman
125
BigFisherman 2014.03.04 04:08  
jjc:
Try the attached version which is updated for use with v600. I haven't fully re-tested it, but it looks as though it works.


Thanks for the update JJC~! I'll try it out.
Antonino Amorosia
35
Antonino Amorosia 2014.03.05 11:59  
Thanks for update!!!
Carl Schreiber
6592
Carl Schreiber 2014.03.30 11:17  

AHHH - I see, here ReadFile is simply define with uchar buffer!

   int ReadFile(int FileHandle, uchar & Buffer[], int BufferLength, int & BytesRead[], int PassAsZero);

Thanks!!

Do Hung
151
Do Hung 2014.06.26 05:02  

Hello, 

 I use both  string ReadLineFromFile and string ReadWholeFile.

But it reads ONLY the 1st character of the file.

1. The line of the file is: 2/74597753/0/1403769366/EURUSD/1.00/1.36337/0.00000/0.00000/0

2. string ReadLineFromFile and string ReadWholeFile. gets ONLY --> 2 (the fist). 

 

Any one has same problem like me?

Please support.

 

Thanks! 

12
To add comments, please log in or register