ShellExecute, what am i doing wrong? - Solved.

 

Just trying to test this and no way to run any external program from the expert... could you help me? I'm getting always error code 2 on the alert popup window. Build 610 Running on a WIndows 7 Ultimate machine.

#import "shell32.dll"
   int ShellExecuteA(int hWnd, string Verb, string File, string Parameter, string Path, int ShowCommand);
#import

int start()

{    

      Shell("cmd.exe", "cd");
      return(0);

} 

bool Shell(string file, string parameters=""){
    #define DEFDIRECTORY NULL
    #define OPERATION "open"       
    #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
    int r=ShellExecuteA(0, OPERATION, file, parameters, DEFDIRECTORY, SW_SHOW);
    if (r <= 32){   Alert("Shell failed: ", r); return(false);  }
    return(true);
}

Damn it. Unicode. ShellExecuteW instead. Thanks.
 
coiler:

Just trying to test this and no way to run any external program from the expert... could you help me? I'm getting always error code 2 on the alert popup window. Build 610 Running on a WIndows 7 Ultimate machine.

Please read some of the many, many threads and posts about calling Functions within DLLs . . . the "new" mql4 uses Unicode not ANSI so you need the Unicode version of the function call if there is one . . . ShellExecuteW

Unicode and ANSI names

ShellExecuteW (Unicode) and ShellExecuteA (ANSI)



 

Hi again,

@RaptorUK, is there any way to know from the EA if is using Unicode or ANSI?, to allow the EA be compatible. In other words, choose ShellExecuteW or ShellExecuteA from the EA without modify the code manually.

Best.

 
coiler:

Hi again,

@RaptorUK, is there any way to know from the EA if is using Unicode or ANSI?, to allow the EA be compatible. In other words, choose ShellExecuteW or ShellExecuteA from the EA without modify the code manually.

Best.

If its compiled in a MetaEditor from a build later than 509 it's using Unicode . . . as far as I am aware . . .

From here: mql4 changes

Strings are now presented in Unicode format, though they were in ANSI format (single byte ones) before. That should be considered if the program uses DLLs and passes string variables to them.

 
Thank you Sir.