Get File Modification Time?

 

Hi All

I have an expert which reads data from a external file and executes trades based on the information inside this file, I don't want my expert to open and read this file on every tick. does anyone know how to use any windows DLL ( likes shell32.dll or kernel32.dll) to query the last modification time of this file, so I can put my logic inisde my code to decide when I need to open and read this file

Thanks

Tom

 

Yeah, I know what you mean. That's sth. I'd like to know, too.

Could some of you knowing how to handle these Windows DLLs write some little tutorial or sth.? There really almost no information about using these DLLs.


Daniel

 

have you ever considered going to a windows programming site? or... horror of horror's MS home, MS has masses of documentation on HOWTO use windows api


shoot over to MS for instance:

MSDN Developer Centers and Resource Centers pull together content and resources around specific products and technologies. They connect you to code samples, community sites, technical articles and documentation, upcoming events, and much more. Each Developer Center gives you a clear road map to understanding and working with your technology of choice.



http://msdn.microsoft.com/en-us/aa937802.aspx


not forgetting this site for masses of posts on howto run dll from mql - take advantage of that top right search box !!!



enjoy

 

Hi ukt,


sure I read a lot of docs about WinApi programming. However, I always have problems using this knowledge for implementing the DLL's function in my MQL4 code. The problem is that there are so many dataTypes which are not available in MQL4 but are returned by Window's DLL's functions, so how to deal with that?

An example of where I get stuck is the simple task of getting a string array of the fileNames in a given Folder. How to use GetFirstFile and GetNextFile? I would need to save the handle returned by GetFirstFile() for passing it to GetNextFile() but should I use int for that like for FileOpen()'s handle? Anyways, MT4 often crashes when I try to get it to work.

Thanks for your tips, friends.


Daniel

 

but... "How to use GetFirstFile and GetNextFile?" somewhere recent on forum code was written/posted by support to do this - was this your thread?

ah just found - https://forum.mql4.com/6893

so not 'get it' regards your queries.

tbh

all the win stuff read - gives data types yes?

u not need same data type! eg, win may use long pointer or something... but all gotta do is learn how it is stored: how many bits? are the bits in any particular format?

see what getting at? from above: if long pointer uses 32bits, and no format - is just 32bit number. Then u can use mql int.

if long pointer uses 64bits instead then you use mql double - remember, a double can hold an interger number, yes? so in this example is holding a win 64bit long pointer.

when you pass the datum back to dll, what is the dll expecting? an address to a datum? a physical datum? ..., these question u answer by looking at interface/header doc to the function(s) used in the dll

even arrays - mql can shove strings or arrays around via address to array/*str/whatever... remember mql functions can have formals that expect address int& anInt[] or expect datum int anInt where the address is concerned, is memory loc of datum(s) and for datum, is actual value passed into function... (MQL4 Reference - Basics - Variables - Formal parameters)

Seriously... is all out there, as Lister said brutal!!!


you can for sure learn HOWTO by yourself and the really cool thing is that once get working all by yourself, you will never ever have to have hassle of messin around on forums and reading gunk like I drone on about ;o)


sure forum is cool, but hey! the real fun/power is the DIY method for sure!



See ya Daniel

 

thanks for this elaborated answer. I really appreciate it. I just know I have seen Rosh's answer in the GetNextFileThread()...



Sincerely,


Daniel.

 

Daniel - fwiw, please do consider posting [as you go along your MT travels], synopsis of your achievements/learning - gained from help in forum and even... your own self-help.

Ok... I am being completely selfish here, but tbh, is for me at least - tremendous 'added value' to read [and archive on my hd ;] solutions/workarounds whatever, that people post.


So then, guess I'm asking that you and any others that read this, to consider a quick post on your respective threads.


For instance, your use of the dll routines and the 'issues' and solutions you come up with etc, am for sure many others would greatly enjoy and of course, benefit too - from your quicky post!


Loadsa coding fun to all!



(may the gods prove magnanimous when mql5 appears cuz reckon gonna need it :o)


 
well...I think I am seeing what you mean, at least a little. I guess it's a little like the openSourcePhilosophy. I am using Linux so I like this idea ;) But how do you really imagine doing this?
 
http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
TT_FX1:

Hi All

I have an expert which reads data from a external file and executes trades based on the information inside this file, I don't want my expert to open and read this file on every tick. does anyone know how to use any windows DLL ( likes shell32.dll or kernel32.dll) to query the last modification time of this file, so I can put my logic inisde my code to decide when I need to open and read this file

Thanks

Tom


See msdn (http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx) and FindFirstFile/FindNextFile
 
Rosh:
http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
TT_FX1:

Hi All

I have an expert which reads data from a external file and executes trades based on the information inside this file, I don't want my expert to open and read this file on every tick. does anyone know how to use any windows DLL ( likes shell32.dll or kernel32.dll) to query the last modification time of this file, so I can put my logic inisde my code to decide when I need to open and read this file

Thanks

Tom

See msdn (http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx) and FindFirstFile/FindNextFile

Hello Rosh

Thanks, would you mind showing us a small sample code of how to use GetFileAttributesEx in MQL4 to obtain the file modification date, there are some sample code for C/C++ on the web, but not for MQL4, I m a bit confused of those parameters likes

__in LPCTSTR lpFileName,
__in GET_FILEEX_INFO_LEVELS fInfoLevelId,
__out LPVOID lpFileInformation

Thnaks Much

Tom

 

See topic GMT from external Source and msdn ( FileTimeToSystemTime )



//+------------------------------------------------------------------+
//|                                                CheckFindFile.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
#property show_inputs
 
#import "kernel32.dll"
int  FindFirstFileA(string path, int& answer[]);
bool FindNextFileA(int handle, int& answer[]);
bool FindClose(int handle);
bool FileTimeToSystemTime(int ft[],int & st[]);
int  GetTimeZoneInformation(int& TZInfoArray[]);
#import
 
int    nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;
int    TZInfoArray[43];
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int LP[82];
   int FileTime[2];
   int SystemTime[4];
   int gmt_shift=0;
   int ret=GetTimeZoneInformation(TZInfoArray);
   if(ret!=0) gmt_shift=TZInfoArray[0];
   Print("Difference between your local time and GMT is: ",gmt_shift," minutes");
   if(ret==2) 
      {
      Print("ret=2");
      gmt_shift+=TZInfoArray[42];
      }
   Print("Current difference between your local time and GMT is: ",gmt_shift," minutes");
   
   int handle = FindFirstFileA(TerminalPath() + "\experts\*.mq4",LP);
   //Print("error = ", GetLastError());
   Print(bufferToString(LP));
   FileTime[0] = LP[1];
   FileTime[1] = LP[2];
   if (FileTimeToSystemTime(FileTime,SystemTime))
      {
      //---- parse date and time from array
         nYear=SystemTime[0]&0x0000FFFF;
         nMonth=SystemTime[0]>>16;
         nDay=SystemTime[1]>>16;
         nHour=SystemTime[2]&0x0000FFFF;
         nMin=SystemTime[2]>>16;
         nSec=SystemTime[3]&0x0000FFFF;
      //---- format date and time items
         string time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec);
         Print("File created at: ",time_string);
 
         datetime local_time=StrToTime(time_string);
         Print("Corrected creation time is: ",TimeToStr(local_time-gmt_shift*60,TIME_DATE|TIME_SECONDS));
 
      }
   ArrayInitialize(LP,0);
/*
   while (FindNextFileA(handle,LP))
      {
      Print(bufferToString(LP));
      ArrayInitialize(LP,0);
      }
*/
   if (handle>0) FindClose(handle);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string FormatDateTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec)
  {
   string sMonth,sDay,sHour,sMin,sSec;
//----
   sMonth=100+nMonth;
   sMonth=StringSubstr(sMonth,1);
   sDay=100+nDay;
   sDay=StringSubstr(sDay,1);
   sHour=100+nHour;
   sHour=StringSubstr(sHour,1);
   sMin=100+nMin;
   sMin=StringSubstr(sMin,1);
   sSec=100+nSec;
   sSec=StringSubstr(sSec,1);
//----
   return(StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
string bufferToString(int buffer[])
   {
   string text="";
   
   int pos = 10;
   for (int i=0; i<64; i++)
      {
      pos++;
      int curr = buffer[pos];
      text = text + CharToStr(curr & 0x000000FF)
         +CharToStr(curr >> 8 & 0x000000FF)
         +CharToStr(curr >> 16 & 0x000000FF)
         +CharToStr(curr >> 24 & 0x000000FF);
      }
   return (text);
   }  
//+------------------------------------------------------------------+
Reason: