Download MetaTrader 5

ShellExecuteA call only works one time

To add comments, please log in or register
milfordT
128
milfordT  
#import "shell32.dll"
int ShellExecuteA(int hWnd,int lpVerb, string lpFile,int lpParameters,int lpDirectory,int nCmdShow);
#import
...
...
int init()
{     // open init file
      ShellExecuteA(0,0,"C:\\Users\\OSR2\\EA2.bat",0,0,SW_SHOW);
...

The above ShellExecuteA call only works the first time the EA is loaded.  If I unload the EA and load it again, 
it will not work and the following error appears in the experts tab:

'ShellExecuteA' call from dll 'shell32.dll' critical error c00000005 at 754C0063

To get it to work again, I have to close MT4 and start it again.

Any help on this one would be greatly appreciated.

Thanks,
Paule Panke
123
Paule Panke  

your import declaration is wrong. it needs to be like this:

#import "shell32.dll"

   int  ShellExecuteA(int hWnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);

#import

do not pass 0 as verb but a real operation type. if you need to pass a null pointer pass a real null pointer. 0 as a string parameter will get converted to "0", not what you want. you get a real one with an uninitialized string, ie

string sNull; // NULL pointer as long as not initialized

ShellExecuteA(..., ..., ..., sNull, sNull, 0);

evaluate the return value if it's still not working.

regards

mrmedia
342
mrmedia  
paulepanke:

your import declaration is wrong. it needs to be like this:

do not pass 0 as verb but a real operation type. if you need to pass a null pointer pass a real null pointer. 0 as a string parameter will get converted to "0", not what you want. you get a real one with an uninitialized string, ie

evaluate the return value if it's still not working.

regards

no -  "int, int, string" allows passing NULL per forexfactory eg.

 

It ought to work. This works everytime -

ShellExecuteA(0,0,"notepad.exe",0,0,SW_SHOW);

 might help 

 #include <WinUser32.mqh>  
 #define SW_SHOW             5
phi nuts
2181
phi nuts  

ShellExecute at MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx


 

This below, is, interesting ;)

string sNull; // NULL pointer as long as not initialized
milfordT
128
milfordT  

Yes, I can get the notepad call to always work.  Maybe it's my batch file. 

All it does is copy one file I made to another.

 

See attached.

milfordT
128
milfordT  

I don't see attachment so I'll put it here:

copy c:\Users\OSR2\JUNK.txt c:\Users\OSR2\JUNK2.txt
pause
whroeder1
15561
whroeder1  
try
Shell("C:\\Users\\OSR2\\EA2.bat");
Shell("cmd.exe", "/C \"C:\\Users\\OSR2\\EA2.bat\"");
////////////////////////////////////////////////
#import "shell32.dll"
   int ShellExecuteA(int hWnd, string Verb, string File, string Parameter, string Path, int ShowCommand);
#import
bool Shell(string file, string parameters=""){
    #define DEFDIRECTORY NULL
    #define OPERATION "open"    // or print
    #define SW_HIDE             0   // http://www.metatrader4.com/forum/1476
    #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
    int r=ShellExecuteA(0, OPERATION, file, parameters, DEFDIRECTORY, SW_SHOWNORMAL);
    if (r <= 32){   Alert("Shell failed: ", r); return(false);  }
    return(true);
}
lnlsoftware
7
lnlsoftware  

Подскажите!

Почему мне выдает ошибку при выполнении команды ShellExecuteA, номер которой 2.

Я написал следующее:

#import "C:\WINDOWS\system32\shell32.dll"

int ShellExecuteA(int hWnd,int lpVerb, string lpFile,int lpParameters,int lpDirectory,int nCmdShow);

#import

....

string NullStr = "NULL";

Print(ShellExecuteA(NULL,0,"C:\\Program Files\\GetRight\\GetRight.exe /URL: http://www.dailyfx.com/files/Calendar-03-09-2014.csv /FILE:Calendar.csv /W /O",NullStr,NullStr,5));

Может я что-то не так написал?

Ту же строку C:\Program Files\GetRight\GetRight.exe /URL: http://www.dailyfx.com/files/Calendar-03-09-2014.csv /FILE:Calendar.csv /W /O выполняю в TotaCommander.

Файл переписывается из сайта.

qjol
3243
qjol  

1) there is a russian forum here

2) you are referring to a thread older than a year probably related to < B579, and you are using (probably) B600 > so you have to use ShellExecuteW

To add comments, please log in or register