Download MetaTrader 5

How to write to Common Data Patch correctly?

To add comments, please log in or register
How to earn at MQL5.community? Come and find out!
Grzegorz Korycki
52287
Grzegorz Korycki 2015.06.16 19:33 

i cannot seem to get it right. I write without problems to allowed //files folder, but i cannot create any file in common data folder. Code goes like this:

int OnInit(void)
{

            string outString = "test1";
            ResetLastError();
            string common_data_path=TerminalInfoString(TERMINAL_COMMONDATA_PATH);
            string filename="";
            StringConcatenate(filename, common_data_path,"\\Files\\testfile");
            Alert("cdp=", filename);  		//debug
            int filehandle=FileOpen(filename,FILE_WRITE|FILE_BIN);
            if(filehandle!=INVALID_HANDLE)
            {
               FileWriteString(filehandle, outString);
               FileClose(filehandle);
            } else Alert("Error - problem saving file: ",GetLastError());
            
            return(INIT_SUCCEEDED);
}

 i get ERROR 5002 (too long file name) error all the time both in MT5 and MT4. How do I do it right?

Alain Verleyen
Moderator
30742
Alain Verleyen 2015.06.16 20:14  
Grzegorz Korycki:

i cannot seem to get it right. I write without problems to allowed //files folder, but i cannot create any file in common data folder. Code goes like this:

 i get ERROR 5002 (too long file name) error all the time both in MT5 and MT4. How do I do it right?

You don't need to add the path to the file name.

int filehandle=FileOpen(filename,FILE_WRITE|FILE_BIN|FILE_COMMON);
Grzegorz Korycki
52287
Grzegorz Korycki 2015.06.16 20:28  
Alain Verleyen:

You don't need to add the path to the file name.

Thank You! I was getting frustrated.
To add comments, please log in or register