GetDiskFreeSpaceExA

 
#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

 
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);
}
 
  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.

 
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"... :)
 
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!
 
ttechnik:

THX, My monitor's wide is 30"... :)
It's not about the inches it's about the number of pixels . . .
 

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

Print(TerminalInfoInteger(TERMINAL_DISK_SPACE));
 
angevoyageur:

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


thx
 
ttechnik:

thx

IN the Build 600:

Replace GetDiskFreeSpaceA to GetDiskFreeSpaceW

 
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!

 
ydrol:

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


:) THX
Reason: