Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has classes?
mojdk
8
mojdk 2015.02.17 20:00 

Hi

 I am totally new to MQL4, but I am learning. What I want to achieve is to execute a Python script when a certain event occur. 

I got the event and everything done, but I can't seem to get the MQL4 implementation working, so I can in fact execute it. This is the last piece in my puzzle.

So I've been Google'ing around, and it appears that you can import a shell32.dll Windows file, and use a method from there called ShellExecuteA, but I know very little about Windows programming, and neither can I get a "demo" code to work.

Can it be because I am using a 64 bit version of Windows? 

This is the code I've found:

//+------------------------------------------------------------------+
//|                                             ShellExecuteTest.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

/* ShellExecute defined in MSDN as
HINSTANCE ShellExecute(HWND hwnd, LPCTSTR lpVerb,LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory,INT nShowCmd);

Look http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp
for detailed information.*/

//---- let's define nShowCmd values
#define SW_HIDE             0
#define SW_SHOWNORMAL       1
#define SW_NORMAL           1
#define SW_SHOWMINIMIZED    2
#define SW_SHOWMAXIMIZED    3
#define SW_MAXIMIZE         3
#define SW_SHOWNOACTIVATE   4
#define SW_SHOW             5
#define SW_MINIMIZE         6
#define SW_SHOWMINNOACTIVE  7
#define SW_SHOWNA           8
#define SW_RESTORE          9
#define SW_SHOWDEFAULT      10
#define SW_FORCEMINIMIZE    11
#define SW_MAX              11

//---- we need to define import of SHELL32 DLL
#import "shell32.dll"
//---- defining ShellExecute
/* Normally we should define ShellExecute like this:
int ShellExecuteA(int hWnd,string lpVerb,string lpFile,string lpParameters,string lpDirectory,int nCmdShow);

But, we need to keep lpVerb,lpParameters and lpDirectory as NULL pointer to this function*/
//---- So we need to define it as (look: "string" parameters defined as "int" to keep them NULL):
int ShellExecuteA(int hWnd,int lpVerb,string lpFile,int lpParameters,int lpDirectory,int nCmdShow);
//---- we need to close import definition here
#import
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//---- let's do it!
   ShellExecuteA(0,0,"C:\\Windows\\System32\\notepad.exe",0,0,SW_SHOW);
//----
   return(0);
  }
//+------------------------------------------------------------------+
Alain Verleyen
Moderator
28704
Alain Verleyen 2015.02.17 21:21  
You need to use ShellExecuteW, the unicode version.
whroeder1
13656
whroeder1 2015.02.17 22:01  
/
To add comments, please log in or register