Does anyone know how to use the GetSystemTime() function from kernel32.dll ? - page 2

 
wemersonrv: Because user that runs MetaTrader, has low privileges and need to be Admin!!
That you should have known. SetLocalTime function (Windows):
The calling process must have the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. The SetLocalTime function enables the SE_SYSTEMTIME_NAME privilege before changing the local time and disables the privilege before returning. For more information, see Running with Special Privileges.
 
Wemerson Guimaraes:

Ok, thanks... I'm sorry for my mistake.

I would to write SetLocalTime() on the title and not GetSystemTime().

And Yes, i do a google search before ask here... but i just found about how to use GetSystemTime()/GetLocalTime() in mql4, but nothing about SetSystemTime()/SetSystemTime().

How can import the dll call i know, but i cannot know how to format the date value to send to the SetLocalTime() function. Below in this thread has a code that i trying to make...

For the record, here a code to get system and local time from DLL... I think this is irrelevant because we have TimeLocal() and TimeGMT() to get those values.... but it's a good exercise.

 

Here a code that i am trying to change computer local time, but not works:

Thanks for this GetSystemTime() code
 

Hi there, 

I know the topic is too old but just in case I would like to note here : 


As you see on "https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types" the WORD type is unsigned short. 


This works for me, on Windows 10 64 bit , MetaTrader version 4.00 build 1345, MetaEditor version : 5.00 build 2387


#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

struct _SYSTEMTIME {
      ushort wYear;
      ushort wMonth;
      ushort wDayOfWeek;
      ushort wDay;
      ushort wHour;
      ushort wMinute;
      ushort wSecond;
      ushort wMilliseconds;
   };

#import "Kernel32.dll"
   void GetSystemTime(_SYSTEMTIME& st); // Working fine!
#import


_SYSTEMTIME st;

int OnInit()
  {
//---
 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  GetSystemTime(st);
  Comment(st.wMilliseconds);
   
  }
//+------------------------------------------------------------------+
Windows Data Types (BaseTsd.h) - Win32 apps
Windows Data Types (BaseTsd.h) - Win32 apps
  • 2018.05.31
  • QuinnRadich
  • docs.microsoft.com
The data types supported by Windows are used to define function return values, function and message parameters, and structure members.
Reason: