Features of the mql5 language, subtleties and tricks - page 198

 
Vladimir Simakov:
Update: on x86 architecture - cpuid prsessor instruction. The msvs has __cpuid(int[4],int) and __cpuidex(int[4],int,int). Examples are available online.

Decided to discard the processor information - it doesn't show anything.

I've settled on the disk, or rather its partition, as there is no way to determine the number of the whole device.

One doubt, are the data types correct?

#property strict

#import "kernel32.dll"
bool GetVolumeInformationW(string RootPathName,
                           ushort VolumeNameBuffer,
                           uint VolumeNameSize,
                           uint &VolumeSerialNumber[],
                           uint MaximumComponentLength,
                           uint FileSystemFlags,
                           ushort FileSystemNameBuffer,
                           uint FileSystemNameSize);
#import
//+------------------------------------------------------------------+
void OnStart()
  {
   Print(SystemDriveSerialNumber("C"));
//---
  }
//+------------------------------------------------------------------+

//-------------------------------------------------------------------------------------------------------------------
string SystemDriveSerialNumber(string sDrive)
  {
   uint iVolumeSerialNumber[1]= {0};
   string sVolumeSerialNumber="";
   if(GetVolumeInformationW("C:\\", NULL, 15, iVolumeSerialNumber, 0, 0, NULL, 15))
     {
      sVolumeSerialNumber=IntegerToHexString(iVolumeSerialNumber[0]);
      sVolumeSerialNumber=StringSubstr(sVolumeSerialNumber,0,4)+"-"+StringSubstr(sVolumeSerialNumber,4);
     }
   return(sVolumeSerialNumber);
  }
//+--------------------------------
string IntegerToHexString(uint num)
  {
   char __hex[]= {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
   int len=0,k=0;
   char buff[64];
   do
     {
      uint n=num&0xF;
      buff[len] = __hex[n];
      len++;
      num>>=4;
     }
   while(num!=0);

   for(; k<len/2; k++)
     {
      buff[k]^=buff[len-k-1];
      buff[len-k-1]^=buff[k];
      buff[k]^=buff[len-k-1];
     }
   return CharArrayToString(buff,0,len);
  }
//+------------------------------------------------------------------+
 
Vitaly Muzichenko:

Decided to discard processor information - it doesn't show anything.

I've settled on the disk, or rather its partition, as there is no way to determine the number of the whole device.

I have one doubt, are the data types correct?

The motherboard ID is correct.

 
Valeriy Yastremskiy:

The motherboard ID is correct.

Is there a code example, can you show me?

 
Vitaly Muzichenko:

Is there a sample code, can you show me?

I can't find the serial number of the board in the µl.

wmic baseboard get serialnumber

in cmd

 
Valeriy Yastremskiy:

How to get the serial number of the board in the µl I have not found.

wmic baseboard get serialnumber

in cmd

I couldn't find it either.

 
Vitaly Muzichenko:
...

One doubt is whether the data types are written correctly?

#define  BOOL bool
#define  LPWSTR string&
#define  LPCWSTR const LPWSTR
#define  DWORD uint
#define  LPDWORD DWORD&

BOOL GetVolumeInformationW(
  LPCWSTR lpRootPathName,
  LPWSTR  lpVolumeNameBuffer,
  DWORD   nVolumeNameSize,
  LPDWORD lpVolumeSerialNumber,
  LPDWORD lpMaximumComponentLength,
  LPDWORD lpFileSystemFlags,
  LPWSTR  lpFileSystemNameBuffer,
  DWORD   nFileSystemNameSize
);

Somehow)

upd: adapted to mql-signatures

 
Vladimir Simakov:

Somehow)

upd: adapted for mql-signatures

What is the point of #define constructions applied once, if you can put types into a function at once and not stretch the code?

 
Vitaly Muzichenko:

What is the point of #define constructions used once, if you can put types into a function at once and not stretch the code?

the point is that you can read and/or use the native WinAPI function signature

 
Igor Makanu:

the sense that it is possible to read and/or use a native WinAPI function signature

Maybe, but the question is exactly this

Forum on trading, automated trading systems and strategy testing

Peculiarities of mql5, tips and tricks

Vitaly Muzichenko, 2021.02.28 00:21

What is the use of #define constructions used once, if you can immediately write the types in the function , and not to stretch the code?

Is there some advantage of defines?

 
Vladimir Simakov:

Somehow)

upd: adapted for mql-signatures

WinAPI mql bible has this function

int  GetVolumeInformationW(
 const string root_path_name,
 ushort &volume_name_buffer[],
 uint volume_name_size,
 uint &volume_serial_number,
 uint &maximum_component_length,
 uint &file_system_flags,
 ushort &file_system_name_buffer[],
 uint file_system_name_size
);

Your types are different, they must be from C#.

#define  BOOL bool
#define  LPWSTR string&
#define  LPCWSTR const LPWSTR
#define  DWORD uint
#define  LPDWORD DWORD&

BOOL GetVolumeInformationW(
  LPCWSTR lpRootPathName,
  LPWSTR  lpVolumeNameBuffer,
  DWORD   nVolumeNameSize,
  LPDWORD lpVolumeSerialNumber,
  LPDWORD lpMaximumComponentLength,
  LPDWORD lpFileSystemFlags,
  LPWSTR  lpFileSystemNameBuffer,
  DWORD   nFileSystemNameSize
);

---

So my question is: where is correct?