shell command?

 
Is there a way to run an external EXE from MQ4, similar to the system( ) or shell( ) command?
 
Yes, you can call ShellExecute directly from your Expert Advisor.
Don't forget to import the shell32.dll in your code:

#import "sell32.dll"




Note: You have to enable "Allow Dll imports".

 
Thanks.

I get a compile error: 'ShellExecute' - function is not defined. I do have #import "Shell32.dll" at the top of the file.

Any thoughts? Also, can you provide an example of a ShellExecute( ) from MQ4?

Thanks again!
Alan
 
Thanks.

I get a compile error: 'ShellExecute' - function is not defined. I do have #import "Shell32.dll" at the top of the file.

Any thoughts? Also, can you provide an example of a ShellExecute( ) from MQ4?

Thanks again!
Alan


Please notice "<,>" brackets, try it like this #import <Shell32.dll>.
 
Thanks.

I get a compile error: 'ShellExecute' - function is not defined. I do have #import "Shell32.dll" at the top of the file.

Any thoughts? Also, can you provide an example of a ShellExecute( ) from MQ4?

Thanks again!
Alan


Please notice "<,>" brackets, try it like this #import <Shell32.dll>.


#inport <Shell32.dll> gives a compile error. #import "Shell32.dll" does not, but then I get the "function not defined" error.

Help?! Anyone have an example of ShellExecute( )'s use in MQ4?

Alan
 
Alan,
Look at this simple script. Read comments attentively.
//+------------------------------------------------------------------+
//|                                             ShellExecuteTest.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe?utm_campaign=MQL5.community",0,0,SW_SHOW);
//----
   return(0);
  }
//+------------------------------------------------------------------+



It really works!

 
Also, please remember that all functions which have strings as parameters in most cases have two definitions:

SomeFunctionA - non-unicode function
SomeFunctionW - unicode function.

Using MQL4 you need to call non-unicode functions. So, ShellExecute can be called as ShellExecuteA.
 
Thanks very much! It's working.

And now for the natural next question - how to cause the parent process to wait for the child to finish? My research indicates that you need to use CreateProcessA, WaitForSingleObject, and CloseHandle.

Does anyone have examples of the use of these API calls from MQ4? I got the #import "kernel32.dll" working, and even the function definitions, but it looks like I need to pass a struct by reference and I'm not sure MQ4 handles that.

Thanks again,
Alan
 
Thanks, Arthur.
 
Alan,
Unfortunately, MQL4 does not support struct definition. So, in this case you'll need to call your own function writed on C++ (or something else) in DLL, and just call it.
I think it is one & easy way to do it.
Reason: