Access violation write to 0x00000000 with ShellExecuteW

To add comments, please log in or register
Sol Dev
1044
Sol Dev  

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
6850
Sergey Eremin  

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
1044
Sol Dev  
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.

pips4life
123
pips4life  

A 2 year old thread, but I ran into the same error message in my code and found a solution for at least my problem.

My main indicator code had defined a global variable array without specifying any size:  int myarray[];  

I wrote a bunch of code in the start() function that worked perfectly.  It included an ArrayResize(myarray,43), but did so only *if* the array was used.  (I was trying not to allocate any memory unless the feature was enabled).

All was working fine, but for better portability and code structure, I moved some one-time-only steps into init(), which in turn called a function that included the ArrayResize.  Now, my otherwise identical code flow got the error:

Access violation write to 0x00000000

I was baffled, because the code was obviously the same commands, only slightly reorganized for init() and a custom function to perform the same initialization steps, followed by repetitive steps in start().

At a deeper level, the function makes some calls to Windows dll time functions, but as I said, when everything was done only by code in the start() level, it all worked fine! 

For the required "access", it apparently matters when and by-what function the array gets resized.


The solution for my problem is to pre-define my original global array variable as the desired array size, e.g.   int myarray[43]

There is no more need for an ArrayResize, and there is no more "Access violation write to 0x00000000" error.


Elsewhere one can find posts with the same error message that appear to be related to passing dynamic arrays around.  It doesn't like resizing them, but defining and passing a fixed array size sometimes resolves it.

To add comments, please log in or register