MT4 Files Functions Replacement.

 

Hi folks,

A lot of people asked me and metaquotes forum about file handling functions.

I think MT4 have a lot of bugs in those functions.

1- They don't work in backtesting

2- They don't write outside "MetaTrader 4\experts\files" path.

Today I opened my Visual C++ and wrote a file handling dll for MT4, I hope you enjoy it, and its source code, and tell me your .

Setup:

1- Extract the "mtguru1.dll" to "MetaTrader 4\experts\libraries" path.

2- Extract "FilesDemo.mq4" to "MetaTrader 4\experts\indicators" path and compile it.

3- Extract "gFiles.mqh" to "MetaTrader 4\experts\include".

4- Load FilesDemo from your Indicators - don't forget to enbable "Allow DLL Import"

5- Enjoy.

Files:
mtguru1.zip  95 kb
 

Feedback

Hi folks,

Any feedback please ?

 

Well, I haven't tested it. But if it works..that is AWESOME!!

I checked out the demo .mq4 file, and it is so simple and elegant. Good work.

The only issue I have is what to do about new lines.

How do I use gFile to write a new line?

 

Thank!

fivewhy:
Well, I haven't tested it. But if it works..that is AWESOME!!

I checked out the demo .mq4 file, and it is so simple and elegant. Good work.

The only issue I have is what to do about new lines.

How do I use gFile to write a new line?

fivewhy,

Thank you very much for your comment.

I think the new line printing issue needs some work from me, Thanks for the notice.

 

well done , but file functions (as well as many other) may be used directly from windows API dlls.

example of file copy function import:

#import "Kernel32.dll"

bool CopyFileA (string source_file, string destination_file, bool if_exist);

with DLLs you can do a lot of things, like SQL database access and so on.

 

where can I find a list of all functions available in kernel32.dll (and other windows .dll's)?

Edit: Found it. See attched.

Files:
kernel32.txt  306 kb
 

That's right, but?

Beluck:
well done , but file functions (as well as many other) may be used directly from windows API dlls.

example of file copy function import:

#import "Kernel32.dll"

bool CopyFileA (string source_file, string destination_file, bool if_exist);

with DLLs you can do a lot of things, like SQL database access and so on.

Beluck,

That's right , but could you give me .mql demo shows me how to use the kernel32 functions CreateFile, OpenFile,WriteFileand ReadFile in MQL4

HANDLE CreateFile(

LPCTSTR lpFileName,

DWORD dwDesiredAccess,

DWORD dwShareMode,

LPSECURITY_ATTRIBUTES lpSecurityAttributes,

DWORD dwCreationDisposition,

DWORD dwFlagsAndAttributes,

HANDLE hTemplateFile

);

HFILE OpenFile(

LPCSTR lpFileName,

LPOFSTRUCT lpReOpenBuff,

UINT uStyle

);

BOOL WriteFile(

HANDLE hFile,

LPCVOID lpBuffer,

DWORD nNumberOfBytesToWrite,

LPDWORD lpNumberOfBytesWritten,

LPOVERLAPPED lpOverlapped

);

BOOL ReadFile(

HANDLE hFile,

LPVOID lpBuffer,

DWORD nNumberOfBytesToRead,

LPDWORD lpNumberOfBytesRead,

LPOVERLAPPED lpOverlapped

);
 

ted

alerts.mqh not part of mtguru1.zip, could not run FilesDemo? Thanking you in advance.

 

gFiles.mqh

sx ted:
alerts.mqh not part of mtguru1.zip, could not run FilesDemo? Thanking you in advance.

sx ted,

I'm sorry, I meant "gFiles.mqh"

To run FilesDemo:

1- Extract the "mtguru1.dll" to "MetaTrader 4\experts\libraries" path.

2- Extract "FilesDemo.mq4" to "MetaTrader 4\experts\indicators" path and compile it.

3- Extract "gFiles.mqh" to "MetaTrader 4\experts\include".

4- Load FilesDemo from your Indicators - don't forget to enbable "Allow DLL Import"

 

ted

CodersGuru, thank u super, have u got equivalent of FileTell()

 

Updated!

sx ted:
CodersGuru, thank u super, have u got equivalent of FileTell()

sx ted,

I've updated the program. Now it includes these functions:

int gFileOpen(string file_name,int mode);

bool gFileWrite(int handle,string data);

bool gFileClose(int handle);

string gFileRead(int handle,int length=0);

void gFileSeek(int handle,int offset, int mode);

bool gFileDelete(string file_name);

int gFileSize(int handle);

int gFileTell(int handle);

bool gFileFlush(int handle);

bool gFileCopy(string source,string distance,bool IfExists);

bool gFileMove(string source,string distance);

I hope you enjoy it.

Files:
mtguru1.zip  88 kb