Always INVALID_HANDLE in the TERMINAL_COMMONDATA_PATH ??

 

Hi,

I am using the code example of the mt4-reference to read some csv-files in the COMMON-Folder - despite my terminals are placed at 'my' folders (keyword: /portable mode) and fail??

My COMMON-Folder (C:\Users\cas\AppData\Roaming\MetaQuotes\Terminal\Common\):

with 18 different csv-files like Key_2015-12-17.csv.

Now I  tried the example code of the mt4 reference:

void OnStart()
  {
//---
   InpFilter = TerminalInfoString(TERMINAL_COMMONDATA_PATH)+"\\*";
   
   string file_name;
   string int_dir="";
   int    i=1,pos=0,last_pos=-1;

   while(!IsStopped()) {
      pos=StringFind(InpFilter,"\\",pos+1);
      if(pos>=0)
         last_pos=pos;
      else
         break;
   }

   //--- the filter contains the folder name
   if(last_pos>=0)
      int_dir=StringSubstr(InpFilter,0,last_pos+1);
   Comment("InpFilter: ",InpFilter,"   Pos \\:",last_pos,"\nNew int_dir: ",int_dir);
   //--- get the search handle in the root of the local folder
   long search_handle=FileFindFirst(InpFilter,file_name,FILE_COMMON); // <= here I get always INVALID_HANDLE ????
   //... skipping the last part of the code example as I always end up with search_handle = INVALID_HANDLE
}


Now I found that there now exists a sub-folder in COMMOM named File. Ok I copied all my csv-Files as well in this sub-folder and tried with:

   InpFilter = TerminalInfoString(TERMINAL_COMMONDATA_PATH)+"\\File\\*";

and failed again - search_handle is nothing but an INVALID_HANDLE.

The error is set to 5002 - wrong file name? But the filename hast to be set by FileFindFirst() ???

Has anybody a working solution?

Can it be that all the mql4 functions for findFile-stuff do not work??

I copied some csv-files directly in ..\MQL4\Files and - it is getting boring - I get search_handle = INVALID_HANDLE??

 
Though I do not use the MQL4 file commands (I lost my temper and I replaced them all by winapi methods), I guess you should not include the system path of the sandbox in front of the file name, but consider the "File" to be the root.
 
Ovo:
Though I do not use the MQL4 file commands (I lost my temper and I replaced them all by winapi methods), I guess you should not include the system path of the sandbox in front of the file name, but consider the "File" to be the root.

Well I want to get rid of the WinApi-File methods as I run into troubles as soon as the same file should be opened and read at the same time by different EA - e.g. at the start of the market on Sundays.

BTW These are genuine MT4 function and the code is part of the reference as an example. I expect it to  be tested and working - no?

 
gooly:

Well I want to get rid of the WinApi-File methods as I run into troubles as soon as the same file should be opened and read at the same time by different EA - e.g. at the start of the market on Sundays.

BTW These are genuine MT4 function and the code is part of the reference as an example. I expect it to  be tested and working - no?

I do not believe anything until I tested it myself.

Regarding your troubles with sharing - MQ re-defined the WINAPI constant FILE_SHARE_WRITE from 0x00000002 to 256, and similar is the FILE_SHARE_READ.

 
Ovo:
Regarding your troubles with sharing - MQ re-defined the WINAPI constant FILE_SHARE_WRITE from 0x00000002 to 256.

What do you mean? What do you do? What about FILE_SHARE_READ?

 

common_flag

[in] Flag determining the location of the file. If common_flag = FILE_COMMON, then the file is located in a shared folder for all client terminals \Terminal\Common\Files. Otherwise, the file is located in a local folder.

The example is wrong.

Files placed in folder :

Terminal\Common\Files\Test

//--- filter
input string InpFilter="Test\\*";

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   
   string file_name;
   string int_dir="";
   int    i=1,pos=0,last_pos=-1;

   while(!IsStopped()) {
      pos=StringFind(InpFilter,"\\",pos+1);
      if(pos>=0)
         last_pos=pos;
      else
         break;
   }

   //--- the filter contains the folder name
   if(last_pos>=0)
      int_dir=StringSubstr(InpFilter,0,last_pos);
   Comment("InpFilter: ",InpFilter,"   Pos \\:",last_pos,"\nNew int_dir: ",int_dir);
   //--- get the search handle in the root of the local folder
   long search_handle=FileFindFirst(int_dir,file_name,FILE_COMMON); // 

  }


 

Well, after coding a Powershell script for a couple of days, I applied the its path habits to mt4 :(

This opens the first file on the Common folder:

   InpFilter="*";
   string file_name;
   string int_dir="";
   int    i=1,pos=0,last_pos=-1;

   while(!IsStopped()) {
      pos=StringFind(InpFilter,"\\",pos+1);
      if(pos>=0)
         last_pos=pos;
      else
         break;
   }

//--- the filter contains the folder name
   if(last_pos>=0)
      int_dir=StringSubstr(InpFilter,0,last_pos+1);
   Comment("InpFilter: ",InpFilter,"   Pos \\:",last_pos,"\nNew int_dir: ",int_dir);
//--- get the search handle in the root of the local folder
   long search_handle=FileFindFirst(InpFilter,file_name,FILE_COMMON);

...
Reason: