Download MetaTrader 5

call GetVolumeInformationA no return values

To add comments, please log in or register
Charles Adriano
469
Charles Adriano  

Hi all...

please tell me what's wrong in this code?


//+------------------------------------------------------------------+
//| GetVolumeInformation.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © free"
#property link "free"
#property strict
#property show_inputs

#import "kernel32.dll"
bool GetVolumeInformationA (string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
int &lpVolumeSerialNumber[],
int &lpMaximumComponentLength[],
int &lpFileSystemFlags[],
string lpFileSystemNameBuffer,
int nFileSystemNameSize);
#import

extern string DriveLetter = "C";

void start()
{
string sNameDisk = DriveLetter + ":\\";
string sNameBuffer = " ";
string sSysNameBuffer = " ";
int dwVSNumber[1] = {0};
int dwMCLength[1] = {0};
int dwFileSF[1] = {0};
bool FunctionOk = GetVolumeInformationA(sNameDisk,
sNameBuffer,
StringLen(sNameBuffer) + 1,
dwVSNumber,
dwMCLength,
dwFileSF,
sSysNameBuffer,
StringLen(sSysNameBuffer) + 1);
if (FunctionOk)
Comment("NameBuffer: \'", sNameBuffer,"\'",
"\nSysNameBuffer: \'", sSysNameBuffer,"\'",
"\nSysNameBuffer: ", sSysNameBuffer,
"\nVSNumber = ", dwVSNumber[0],
"\nMCLength = ", dwMCLength[0],
"\nFileSF = ", dwFileSF[0]);
else
Comment("GetVolumeInformationA not all the requested information was retrieved!"
"\nNameBuffer: \'", sNameBuffer,"\'",
"\nSysNameBuffer: \'", sSysNameBuffer,"\'",
"\nVSNumber = ", dwVSNumber[0],
"\nMCLength = ", dwMCLength[0],
"\nFileSF = ", dwFileSF[0]);

return;
}



maybe a import definition or call parameters?


http://msdn.microsoft.com/en-us/library/windows/desktop/aa364993%28v=vs.85%29.aspx


I need to get a serial number of Hard Disk, but this function not work.

Any idea?

charles

Alain Verleyen
Moderator
29868
Alain Verleyen  
Strings are now Unicode and no more Ansi. You have to adapt your code accordingly. Use GetVolumeInformationW instead of GetVolumeInformationA.
Charles Adriano
469
Charles Adriano  
:)

Work fine now... a lot of thanks...


charles

fagh81
4
fagh81  
Charles Adriano:
:)

Work fine now... a lot of thanks...


charles


Hi Charles Adriano,

I also want to get disk serial number, I have use your code provide but change it to GetVolumeInformationW , but it is not working. Can you share it to me.

//+------------------------------------------------------------------+
//| GetVolumeInformation.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © free"
#property link "free"
#property strict
#property show_inputs

#import "kernel32.dll"
bool GetVolumeInformationW (string lpRootPathName, 
string lpVolumeNameBuffer, 
int nVolumeNameSize, 
int &lpVolumeSerialNumber[], 
int &lpMaximumComponentLength[], 
int &lpFileSystemFlags[], 
string lpFileSystemNameBuffer, 
int nFileSystemNameSize); 
#import

extern string DriveLetter = "C";

void start()
{
string sNameDisk = DriveLetter + ":\\";
string sNameBuffer = " ";
string sSysNameBuffer = " ";
int dwVSNumber[1] = {0};
int dwMCLength[1] = {0};
int dwFileSF[1] = {0};
bool FunctionOk = GetVolumeInformationW(sNameDisk, 
sNameBuffer, 
StringLen(sNameBuffer) + 1, 
dwVSNumber, 
dwMCLength, 
dwFileSF, 
sSysNameBuffer, 
StringLen(sSysNameBuffer) + 1);
if (FunctionOk)
Comment("NameBuffer: \'", sNameBuffer,"\'", 
"\nSysNameBuffer: \'", sSysNameBuffer,"\'", 
"\nSysNameBuffer: ", sSysNameBuffer, 
"\nVSNumber = ", dwVSNumber[0], 
"\nMCLength = ", dwMCLength[0], 
"\nFileSF = ", dwFileSF[0]);
else 
Comment("GetVolumeInformationW not all the requested information was retrieved!"
"\nNameBuffer: \'", sNameBuffer,"\'", 
"\nSysNameBuffer: \'", sSysNameBuffer,"\'", 
"\nVSNumber = ", dwVSNumber[0], 
"\nMCLength = ", dwMCLength[0], 
"\nFileSF = ", dwFileSF[0]);

return;
}





fagh81
4
fagh81  
fagh81:

Hi Charles Adriano,

I also want to get disk serial number, I have use your code provide but change it to GetVolumeInformationW , but it is not working. Can you share it to me.


Hi, can any one help me

To add comments, please log in or register