Download MetaTrader 5

Unable to use Shell32.dll on MQL5

To add comments, please log in or register
sgfxtrader
54
sgfxtrader  

I am running on Windows Vista.

The MT5 is run in AppData\Roaming\MetaQuotes\Terminal\725770E6BE34B17A6EB82115D4D83BD3\

Under MQL5\Scripts, I tried to create a script to open notepad via shell32.dll but was unsuccessful.

runNotepad.mq5

#import "shell32.dll"

int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);

#import


int OnStart()
  {
   ShellExecuteA(0,"Open","C:\windows\notepad.exe","","",SW_SHOW);
   return(0);

  }

Hope to have some advise.

Thank you!

Ilyas
1208
Ilyas  

Use unicode version  ShellExecuteW

Paul
784
Paul  

mql5 posted # :

Use unicode version  ShellExecuteW

 

 

Also I think you would need double backslash on the path. 

ShellExecuteW(0,"Open","C:\\windows\\notepad.exe","","",SW_SHOW);

And since ShellExecuteW returns a result it would be good practice to check it.

Paul

http://paulsfxrandomwalk.blogspot.com/ 

 

sgfxtrader
54
sgfxtrader  

Hi all,

Thank you for the prompt response.

But I still can't make it work in MQL5.

Attached is the source that I am working on.

Hope can have a workable solution.


Thanks!

Files:
Ilyas
1208
Ilyas  
sgfxtrader:

Thank you for message. Fixed. Wait for updates.

After updating try

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

#import "shell32.dll"
int ShellExecuteW(int hwnd,const string Operation,const string File,const string Parameters,const string Directory,int ShowCmd);
#import

void OnStart()
{
   int r = ShellExecuteW(0,NULL,"C:\\windows\\notepad.exe",NULL,NULL,5);
   Print("Shell",r);
}
sgfxtrader
54
sgfxtrader  
mql5:

Thank you for message. Fixed. Wait for updates.

After updating try

Hi!

May I know if the patch will be more complete?

I just found out that I cannot run kernel32.dll too.

e.g:

#import "kernel32.dll"

int WinExec(string NameEx, int dwFlags);

#import

WinExec("notepad",0); -- Script run without executing this, and unloaded itself successfully. 

Ilyas
1208
Ilyas  

Please read MSDN

Runs the specified application.

Note  This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.

UINT WINAPI WinExec(
  __in          LPCSTR lpCmdLine,
  __in          UINT uCmdShow
);
sgfxtrader
54
sgfxtrader  

Hi all!

I am very happy to update you guys that the latest update (v. 250) was timely!

The suggestion posted by Paul at here is working perfectly!

Thank you for this wonderful MetaTrader!

 

To our trading success! 

To add comments, please log in or register