[HELP] Write/Read to files saved outside MT4 directories

 

Hello Gurus,

I am trying to write and read to files which are saved to C:\Folder instead of inside Metatrader 4 folders.

Since MT4 build +600, everything related to import external dd like kernel32 has changed the way they previously working well. Please see part of below code to help if you are successful. Great Thanks in advance :)

#property copyright "Copyright © 2011"
#property link      ""
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

#import "kernel32.dll"
#define GENERIC_READ    0x80000000
#define GENERIC_WRITE   0x40000000
#define FILE_SHARE_READ                 0x00000001
#define FILE_SHARE_WRITE                0x00000002
#define FILE_SHARE_DELETE               0x00000004
#define CREATE_NEW      1
#define CREATE_ALWAYS   2
#define OPEN_EXISTING   3
#define OPEN_ALWAYS     4
#define INVALID_HANDLE -1

double so_lot_buy=2.6, sl_buy=1.1010, target_buy=1.2010, so_lot_sell=1.2, target_sell=119.123, sl_sell=119.743;
string izzsl = "fgf", izzsh="sdfsdfa";

int CreateFileA(
      string   FileName,
      int      DesiredAccess,
      int      dwShareMode,
      int      lpSecurityAttributes,
      int      dwCreationDistribution,
      int      dwFlagsAndAttributes,
      int      hTemplateFile
);   
 
int CreateFileW(
 
qjol:

Thank for your suggestion. I will try asap when market returns to work next Monday then report back here. :)
 
 
qjol:

Hello there,

I confirm that your suggestion to use CreateFileW() working great. Big Thanks :) 

 

Hey, can someone please post a sample code of:

1. File reading with that function

2. File writing with that function

I am having a have time understanding what should i pass as parameters in that function.

For instance my file is located: Z:\Documents\Python\workfile.txt, how can i access it?

Thanks!

 
wisenlucky:

Hey, can someone please post a sample code of:

1. File reading with that function

2. File writing with that function

I am having a have time understanding what should i pass as parameters in that function.

For instance my file is located: Z:\Documents\Python\workfile.txt, how can i access it?

Thanks!


By saving inside of the sandbox.

Those file restrictions are security issues.

 
Marco vd Heijden:

By saving inside of the sandbox.

Those file restrictions are security issues.


Thanks, but that doesn't get me any closer to understanding  CreateFileW parameters.

 
You find the docs for CreateFileW Microsoft sites - just google, I hop you know how to do this!
 
Carl Schreiber:
You find the docs for CreateFileW Microsoft sites - just google, I hop you know how to do this!

Does comment like this make you feel better and smarter? 

Of course i googled it before posting, and microsoft website doesnt really have a single code sample. And in the microsoft docs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx - it's wasn't clear enough how should i use parameters.

Please don't bother replying Carl Shreiber. Doesn't feel like you know the topic well enough to help.

CreateFile function (Windows)
  • msdn.microsoft.com
Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe. The function returns a handle that can be used to access the file or device for various types of I/O depending on the file or...
 

You can take a look at examples in CodeBase:


https://www.mql5.com/en/code/386

https://www.mql5.com/en/code/8577


Regards.

FileUnlimited
FileUnlimited
  • votes: 26
  • 2015.01.28
  • Комбинатор
  • www.mql5.com
Library for working with files using WinAPI without location limitations. At present time the read-only mode is implemented. The library will be updated. FileUnlimited.mqh, FileUnlimitedConstants.mqh, and StringUtils.mqh must be copied to the terminal_data_folder\MQL5\Include\TheXpert; ConstFileUnlimited.mqh library must be copied to the...
Reason: