Download MetaTrader 5
To add comments, please log in or register
Use MQL5 Cloud Network. Test robots at a super speed!
ttechnik
256
ttechnik 2014.01.21 13:29 
#import "kernel32.dll"
 
   
   bool GetDiskFreeSpaceA  (string& as_dir, double& al_sectorspercluster, double& al_bytespersector, double& al_freeclusters, double& al_totalclusters);
   bool GetDiskFreeSpaceExA(string& as_dir, double& ast_userfreebytes, double& ast_totalbytes, double& ast_totalfreebytes);
#import


.....

string as_dir="C:"+ CharToStr(92)+ CharToStr(92); double ast_userfreebytes, ast_totalbytes, ast_totalfreebytes;
int a=GetDiskFreeSpaceExA(as_dir, ast_userfreebytes, ast_totalbytes, ast_totalfreebytes);
Alert(a, as_dir, " ast_userfreebytes:", ast_userfreebytes, " ast_totalbytes:", ast_totalbytes, " ast_totalfreebytes:", ast_totalfreebytes);
           
double al_sectorspercluster, al_bytespersector, al_freeclusters, al_totalclusters;
a=GetDiskFreeSpaceA(as_dir, al_sectorspercluster, al_bytespersector, al_freeclusters, al_totalclusters);
Alert(a, as_dir, " al_sectorspercluster:", al_sectorspercluster, " al_bytespersector:", al_bytespersector, " al_freeclusters:", al_freeclusters, " al_totalclusters:", al_totalclusters);
           

What is the wrong?

All value is 0.


THX

gchrmt4
356
gchrmt4 2014.01.21 13:48  
ttechnik:

What is the wrong?


The LPDWORD return values from GetDiskFreeSpace() are not the same as "double &". A DWORD is an unsigned 4-byte integer. A double is an 8-byte floating-point number.

Secondly, you cannot pass the address of a single int (or double) variable to a DLL in MQL4. You have to pass an array, of which only the first element then gets used.

For example:

#import "kernel32.dll"
   int GetDiskFreeSpaceA  (string as_dir, int & al_sectorspercluster[], int& al_bytespersector[], int& al_freeclusters[], int& al_totalclusters[]);
#import


void start()
{
   // Does not make a difference, but this is *NOT THE SAME* as "C:"+ CharToStr(92)+ CharToStr(92); 
   string as_dir = "c:\\"; // i.e. the string value C:\   NOT the string value C:\\
   
   // 4 arrays to hold the four LPDWORD return values
   int rv1[1], rv2[1], rv3[1], rv4[1];
   
   // Call GetDiskFreeSpaceA()
   int a = GetDiskFreeSpaceA(as_dir, rv1, rv2, rv3, rv4);
   
   // For convenience, put each of the return values into its own int variable
   int al_sectorspercluster = rv1[0];
   int al_bytespersector = rv2[0];
   int al_freeclusters = rv3[0];
   int al_totalclusters = rv4[0];
   
   Alert(a, as_dir, " al_sectorspercluster:", al_sectorspercluster, " al_bytespersector:", al_bytespersector, " al_freeclusters:", al_freeclusters, " al_totalclusters:", al_totalclusters);
}
whroeder1
13641
whroeder1 2014.01.21 14:21  
  1. gchrmt4:
       // Does not make a difference, but this is *NOT THE SAME* as "C:"+ CharToStr(92)+ CharToStr(92); 
       string as_dir = "c:\\"; // i.e. the string value C:\   NOT the string value C:\\
    
    or
    #define BS "\\" // A single back slash "\"
       string as_dir = "c:"+BS; // i.e. the string value C:\   NOT the string value C:\\

  2. ttechnik:
    Alert(a, as_dir, " al_sectorspercluster:", al_sectorspercluster, " al_bytespersector:", al_bytespersector, " al_freeclusters:", al_freeclusters, " al_totalclusters:", al_totalclusters);
    
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.

ttechnik
256
ttechnik 2014.01.21 21:01  
WHRoeder:
  1. gchrmt4:
    or
  2. ttechnik:
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.


THX, My monitor's wide is 30"... :)
ttechnik
256
ttechnik 2014.01.21 21:02  
gchrmt4:


The LPDWORD return values from GetDiskFreeSpace() are not the same as "double &". A DWORD is an unsigned 4-byte integer. A double is an 8-byte floating-point number.

Secondly, you cannot pass the address of a single int (or double) variable to a DLL in MQL4. You have to pass an array, of which only the first element then gets used.

For example:


thank you very much for your help!
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.01.21 21:39  
ttechnik:

THX, My monitor's wide is 30"... :)
It's not about the inches it's about the number of pixels . . .
Alain Verleyen
Moderator
28651
Alain Verleyen 2014.01.22 13:17  

With the new MT4 (currently beta), you can get free disk space with :

Print(TerminalInfoInteger(TERMINAL_DISK_SPACE));
ttechnik
256
ttechnik 2014.01.25 12:17  
angevoyageur:

With the new MT4 (currently beta), you can get free disk space with :


thx
ttechnik
256
ttechnik 2014.02.09 13:24  
ttechnik:

thx

IN the Build 600:

Replace GetDiskFreeSpaceA to GetDiskFreeSpaceW

ydrol
594
ydrol 2014.02.10 08:18  
WHRoeder:
  1. ttechnik:
    Alert(a, as_dir, " al_sectorspercluster:", al_sectorspercluster, " al_bytespersector:", al_bytespersector, " al_freeclusters:", al_freeclusters, " al_totalclusters:", al_totalclusters);
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.


Looks fine to me on a 24" monitor, with 5 inches to spare too!

ttechnik
256
ttechnik 2014.02.21 11:36  
ydrol:

Looks fine to me on a 24" monitor, with 5 inches to spare too!


:) THX
/ /12
To add comments, please log in or register