Calling WinAPI ReadFile() results in a crash

 

I tried to run the attached simple script in 64bit MT5, but for some reason ReadFile() results in an ugly crash. All other functions imported from kernel32 work fine.

This code also works without problems in MT4 and 32bit MT5.

Any idea what's wrong?

Files:
Test.mq5  3 kb
 
long fileHandle  

 
Mikhail Dovbakh:
long fileHandle  


Changing fileHandle to long doesn't seem to fix the problem.

The culprit turned out to be in the declaration of last argument which is supposed to be declared as long:

bool ReadFile (int fileHandle,char& buffer[],int bytes,int& numOfBytes,long overlapped);

This signature doesn't crash on the 64bit platform.
ReadFile function (Windows)
  • msdn.microsoft.com
Reads data from the specified file or input/output (I/O) device. Reads occur at the position specified by the file pointer if supported by the device. This function is designed for both synchronous and asynchronous operations. For a similar function designed solely for asynchronous operation, see ReadFileEx. Syntax Parameters hFile [in] A...
Reason: