Download MetaTrader 5

Access violation write to 0x00000000 with ShellExecuteW

To add comments, please log in or register
Download MQL5 library codes via MetaTrader. It is convenient!
Sol Dev
833
Sol Dev 2015.12.07 20:02 

Hello, i am actually coding a ShellExecute function to launch web browser by opening an internet shortcut made by :

bool openURL(string url){      
    string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
    filename=IntegerToString(TimeCurrent()+MathRand())+"myurl.URL";
    fullURL=terminal_data_path+"\\MQL4\\Files\\"+filename;
    int handleOPT   = FileOpen(filename, FILE_WRITE|FILE_CSV);
    if (handleOPT < 1){ int GLE = GetLastError(); }
    FileWrite(handleOPT, "[InternetShortcut]");
    FileWrite(handleOPT, "URL="+url);
    FileClose(handleOPT);
    Print(filename);       
    return ( Shell(fullURL) );     // or "cmd.exe", "/C "+file
}

Everything's doing well until i got an error that is often (not anytime) returned by the Shell function itself :

bool Shell(string file, string parameters=""){
    #define DEFDIRECTORY NULL
    #define OPERATION "open"    // or print
    #define SW_SHOWNORMAL 1    
           
    Print("shell execute !");
    int r=ShellExecuteW(0, OPERATION, file, parameters, DEFDIRECTORY, SW_SHOWNORMAL);
    
    if (r > 32) return(true);
    Alert("Shell failed: ",r);
    return(false);   

}

The error is :

2015.12.07 19:54:07.108    Access violation write to 0x00000000

I think it deals with C++ DLL and uchar to string or something ? Any help would be greatly appreciate, as the indicator is not responding anymore after this error print into the console...

Here are the includes i have, for any debugging purpose :

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

Thanks in advance.

Sergey Eremin
4362
Sergey Eremin 2015.12.08 06:36  

Hello!

You can try this variant:

int ShellExecuteW(int hwnd,const string Operation,const string File,const string Parameters, const int Directory,int ShowCmd);
Sol Dev
833
Sol Dev 2015.12.08 09:28  
Sergey Eremin:

Hello!

You can try this variant:

Hello, thank you Sergey. But it didn't help. "Access violation write to 0x00000000" is still present :(

I am investigating it but it's painful.


The ShellExecute is working as the internet browser is launching by the internet shortcut. But right after that, the access violation appear and the indicator is not responding anymore.

To add comments, please log in or register